Replies: 1 comment
-
Hello @maxymed! I'm Dosu, and I'm here to help you solve bugs, answer questions, and guide you as you contribute. While you're waiting for a human maintainer, feel free to ask me anything! To implement hybrid search with LlamaIndex and Pinecone, you are on the right track with using a sparse embedding model subclassed from
Here's a code snippet to illustrate these steps: # Assuming `query` is an instance with necessary attributes
if query.query_embedding is not None:
dimension = len(query.query_embedding)
else:
dimension = self._pinecone_index.describe_index_stats()["dimension"]
query_embedding = [0.0] * dimension
if query.mode in (VectorStoreQueryMode.DEFAULT, VectorStoreQueryMode.HYBRID):
query_embedding = cast(List[float], query.query_embedding)
if query.alpha is not None:
query_embedding = [v * query.alpha for v in query_embedding]
sparse_top_k = query.sparse_top_k or query.similarity_top_k
response = self._pinecone_index.query(
vector=query_embedding,
sparse_vector=pinecone_sparse_vector, # Ensure this is set correctly
top_k=query.similarity_top_k, # Manage dense_top_k results
include_values=True,
include_metadata=True,
namespace=self.namespace,
filter=filter,
)
# Handle sparse results separately if needed
sparse_results = self._sparse_query_with_rank(
query.query_str, sparse_top_k, query.filters
)
# Combine dense and sparse results
all_results = response + sparse_results This setup ensures that hybrid search is correctly implemented by managing the query embedding, applying the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm having issues implementing hybrid search with LlamaIndex and Pinecone.
If I understand correctly, the sparse embedding model should be a subclass of BaseSparseEmbedding, so it can be used to generate the sparse embeddings.
So during upsert I would need to use something like :
vector_store = PineconeVectorStore( pinecone_index=pinecone_index, add_sparse_vector=True, sparse_embedding_model=sparse_embedding_model)
And during query, I don't need to explicitely generate the sparse vectors, I only use:
vector_store = PineconeVectorStore(pinecone_index=pinecone_index, text_key="_node_content", sparse_embedding_model=sparse_embedding_model) # <- points to the same vector store used for upserting vector_index = VectorStoreIndex.from_vector_store(vector_store, embed_model=Settings.embed_model) retriever = VectorIndexRetriever(index=vector_index, similarity_top_k=5, vector_store_query_mode="hybrid")
I think I'm missing something, because I don't see an alpha parameter to mix between sparse and dense, or a dense_top_k, and a sparse_top_k
Beta Was this translation helpful? Give feedback.
All reactions