----------------------
To implement sparse, hybrid, and full-text search with Milvus Vector Store in LlamaIndex, you can follow these steps:
- Sparse Search:
Sparse search is enabled by setting
enable_sparse=True
when initializing the MilvusVectorStore. The default sparse embedding method uses BGE-M3 from FlagEmbedding.
- Hybrid Search:
Hybrid search combines dense and sparse embeddings. To implement it:
- Set
enable_sparse=True
when creating MilvusVectorStore - Configure a hybrid ranker (e.g., RRFRanker or WeightedRanker)
- Use
vector_store_query_mode="hybrid"
when querying
Here's an example of setting up MilvusVectorStore for hybrid search:
vector_store = MilvusVectorStore(
dim=1536,
overwrite=True,
enable_sparse=True,
hybrid_ranker="RRFRanker",
hybrid_ranker_params={"k": 60},
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context
)
To query using hybrid mode:
query_engine = index.as_query_engine(vector_store_query_mode="hybrid")
response = query_engine.query("Your query here")
- Full-text Search:
Full-text search in Milvus is implemented as part of the sparse search functionality. When you enable sparse search, you're essentially enabling full-text search capabilities.
It's important to note that hybrid retrieval is only supported in Milvus 2.4.0 or later. If you're using an earlier version, you'll need to update.