Replies: 1 comment
-
Hello @jja1977 👋 I'm here to help you with any technical questions or issues you may have while we wait for a human maintainer. Let me know how I can assist you! To perform a vector search on two different indexes, retrieve the top 10 results from each index, combine them into a single list of 20 nodes, and synthesize a response from these 20 nodes while keeping the indexes separate, you can use the
Here is a code example to achieve this: import os
import openai
os.environ["OPENAI_API_KEY"] = "sk-..."
openai.api_key = os.environ["OPENAI_API_KEY"]
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
from llama_index.legacy.indices.managed.vectara.retriever import VectaraRetriever
from llama_index.core.query_engine import RetrieverQueryEngine
from llama_index.core.response.notebook_utils import display_response
# Load documents and create indexes
documents_1 = SimpleDirectoryReader(input_files=["path_to_first_document.md"]).load_data()
documents_2 = SimpleDirectoryReader(input_files=["path_to_second_document.md"]).load_data()
index_1 = VectorStoreIndex.from_documents(documents_1)
index_2 = VectorStoreIndex.from_documents(documents_2)
# Initialize the VectaraRetriever for each index
retriever_1 = VectaraRetriever(index=index_1, similarity_top_k=10)
retriever_2 = VectaraRetriever(index=index_2, similarity_top_k=10)
# Perform vector search on each index
nodes_with_scores_1 = retriever_1.retrieve("your query here")
nodes_with_scores_2 = retriever_2.retrieve("your query here")
# Combine the results
combined_results = nodes_with_scores_1 + nodes_with_scores_2
# Use in a Query Engine to synthesize a response
query_engine = RetrieverQueryEngine.from_args([retriever_1, retriever_2])
response = query_engine.query("your query here")
# Display the response
display_response(response) This code initializes two |
Beta Was this translation helpful? Give feedback.
-
Hi,
I would like to do a vector search of two different indexes, returning the top 10 from each. Then, I would like to combine these into a list of 20 nodes and synthesize a response from those 20 nodes. Does anyone know the best way to do this please? I don’t want to combine the indexes, I’d like them separate and I want to return a topK from each, then combine, then synthesize.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions