Skip to content

Commit

Permalink
fix: Fix sparse slice bug in hello_model.py(#2414) (#2417)
Browse files Browse the repository at this point in the history
### What this PR does:
Fixes a bug in `examples/milvus_model/hello_model.py` where indexing a
sparse matrix with `x[0]` caused a `NotImplementedError`.

### Changes made:
- Updated the sparse matrix indexing from `x[0]` to `x[:, [0]]` to use
explicit 2D indexing, which is supported.

Signed-off-by: jinjuan zhou <[email protected]>
Co-authored-by: jinjuan zhou <[email protected]>
  • Loading branch information
zjjzyl and jinjuan zhou authored Dec 23, 2024
1 parent 1a46af1 commit 6da8631
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions examples/milvus_model/hello_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,16 @@ def log(msg):
# BM25EmbeddingFunction usage
log(fmt.format("BM25EmbeddingFunction Usage"))
ef_bm25 = BM25EmbeddingFunction()
docs_bm25 = [
"Artificial intelligence was founded as an academic discipline in 1956.",
"Alan Turing was the first person to conduct substantial research in AI.",
"Born in Maida Vale, London, Turing was raised in southern England.",
]
ef_bm25.load()
embs_bm25 = ef_bm25.encode_documents(docs)
log(f"Embedding Shape: {embs_bm25[0].shape} Dimension: {ef_bm25.dim}")
log(f"Embedding Shape: {embs_bm25[:, [0]].shape} Dimension: {ef_bm25.dim}")

# -----------------------------------------------------------------------------
# SpladeEmbeddingFunction usage
log(fmt.format("SpladeEmbeddingFunction Usage"))
ef_splade = SpladeEmbeddingFunction(device="cpu")
embs_splade = ef_splade(["Hello world", "Hello world2"])
log(f"Embedding Shape: {embs_splade[0].shape} Dimension: {ef_splade.dim}")
log(f"Embedding Shape: {embs_splade[:, [0]].shape} Dimension: {ef_splade.dim}")

# -----------------------------------------------------------------------------
log(fmt.format("Demonstrations Finished"))

0 comments on commit 6da8631

Please sign in to comment.