MultiModalVectorStoreIndex
feature. Here's a brief overview of how you can achieve this:MultiModalVectorStoreIndex
that supports building separate vector stores for different types of data, such as image and text embedding vector stores.MultiModalRetriever
and SimpleMultiModalQueryEngine
components support text-to-text/image and image-to-image retrieval, as well as simple ranking fusion functions for combining text and image retrieval results.MultiModalVectorStoreIndex
to combine these vector stores.MultiModalRetriever
to query across these vector stores based on your specific query requirements.from llama_index.core import VectorStoreIndex index_A = VectorStoreIndex.from_documents(documents_A) index_B = VectorStoreIndex.from_documents(documents_B)
from llama_index.core.retrievers import QueryFusionRetriever retriever = QueryFusionRetriever( [index_A.as_retriever(), index_B.as_retriever()], similarity_top_k=2, num_queries=1, # set this to 1 to use only the original query use_async=True, verbose=True, )
query_engine = index.as_query_engine(retriever=retriever) response = query_engine.query("Your query here")
VectorIndexRetriever
and customize it based on your query. Here's how you can do it:from llama_index.core import VectorStoreIndex, SimpleDirectoryReader # Create vector store for Company A documents_A = SimpleDirectoryReader("path_to_company_A_docs").load_data() index_A = VectorStoreIndex.from_documents(documents_A) # Create vector store for Company B documents_B = SimpleDirectoryReader("path_to_company_B_docs").load_data() index_B = VectorStoreIndex.from_documents(documents_B)
def select_vector_store(query): # Implement your logic here to decide which vector store to use if "Company A" in query: return index_A elif "Company B" in query: return index_B else: return None # If no specific vector store is needed
``
This approach allows you to:
1. Select a specific vector store based on the query content.
2. Bypass the vector stores entirely if the query doesn't require them.
3. Avoid using a query engine when it's not necessary, giving you more control over the retrieval and response generation process.
Remember to implement the
select_vector_store` function according to your specific needs and criteria for selecting the appropriate vector store.from llama_index.core import VectorStoreIndex, SimpleDirectoryReader # Create vector store for Company A documents_A = SimpleDirectoryReader("path_to_company_A_docs").load_data() index_A = VectorStoreIndex.from_documents(documents_A) # Create vector store for Company B documents_B = SimpleDirectoryReader("path_to_company_B_docs").load_data() index_B = VectorStoreIndex.from_documents(documents_B)
from llama_index.core.tools import QueryEngineTool, ToolMetadata tool_A = QueryEngineTool( query_engine=index_A.as_query_engine(), metadata=ToolMetadata( name="company_A_info", description="Provides information about Company A" ) ) tool_B = QueryEngineTool( query_engine=index_B.as_query_engine(), metadata=ToolMetadata( name="company_B_info", description="Provides information about Company B" ) )
from llama_index.core.query_engine import RouterQueryEngine router_query_engine = RouterQueryEngine.from_defaults( [tool_A, tool_B], verbose=True )
response = router_query_engine.query("What are Company A's policies?") print(response)