From 6da86317c120d80dcf3341978d869c5e991cec5d Mon Sep 17 00:00:00 2001 From: zjjzyl Date: Mon, 23 Dec 2024 17:46:41 +0800 Subject: [PATCH] fix: Fix sparse slice bug in hello_model.py(#2414) (#2417) ### 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 Co-authored-by: jinjuan zhou --- examples/milvus_model/hello_model.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/examples/milvus_model/hello_model.py b/examples/milvus_model/hello_model.py index ff61bda62..b40ac1867 100644 --- a/examples/milvus_model/hello_model.py +++ b/examples/milvus_model/hello_model.py @@ -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"))