RouterRetriever
with LLMSingleSelector
. The problem is that the selector prompt in SelectorOutputParser
isn't in the format that I want. I have prompt template like this:SINGLE_SELECTOR_PROMPT_TEMPLATE = ( "### System:\n" "You are a helpful assistant. " "Using only the choices above and not prior knowledge, return " "the choice that is most relevant to the question: '{query_str}'\n" "### User:\n" "Some choices are given below. It is provided in a numbered list " "(1 to {num_choices}), " "where each item in the list corresponds to a summary.\n" "---------------------\n" "{context_list}" "\n---------------------\n" "### Assistant:\n" ) ... retriever = RouterRetriever( selector=LLMSingleSelector.from_defaults( prompt_template_str=SINGLE_SELECTOR_PROMPT_TEMPLATE), retriever_tools=[vs_tool, summary_tool] )
SelectionOutputParser.parse
automatically append a FORMAT_STR
like this prompt_template + "\n\n" + _escape_curly_braces(FORMAT_STR)
which results in: ### System: You are a helpful assistant. Using only the choices above and not prior knowledge, return the choice that is most relevant to the question: 'Summarize the uploaded document' ### User: Some choices are given below. It is provided in a numbered list (1 to 2), where each item in the list corresponds to a summary. --------------------- (1) Useful for retrieving specific context from uploaded documents. (2) Useful to retrieve all context from uploaded documents and summary tasks. Don't use if the question only requires more specific context. --------------------- ### Assistant: ====> This phrase is in the wrong position. The output should be ONLY JSON formatted as a JSON instance. Here is an example: [ {{ choice: 1, reason: "<insert reason for choice>" }}, ... ]
### Assistant:
to right after the FORMAT_STR
?persist_dir
with the same storage context. But I can't have the same storage context because users don't upload documents as the same time => indices will be override when new document arrives.{s3_bucket}/{doc_id}
, maybe it will work. Although, in loading state, I have to use a loop to load all documents' index.SubQuestionQueryEngine
, is there anything with the same function for ContextChatEngine
? Thanks in advance.index_store.json, docstore.json, graph_store.json
do when I persist the index into my file system? And also what is the purpose of them when I later using the persisted index to query? I don't see so much information contained in them. I'm using PostgreSQL VectorStoreIndex with S3 File System. Thanks in advance.User
postgresql table that populates a relationship with the table created by PGVectorStore to mark the owner of documents in the vector store. Something like this:class User(Base): __tablename__ = "users" id = Column(Integer, primary_key=True, index=True) email = Column(String, unique=True, index=True) hashed_password = Column(String) files = relationship("File", back_populates="owner")
sqlalchemy
model but don't know how to make PGVectorStore
uses this instead of the default model.class File(Base): __tablename__ = "data_pg_vector_store" id = Column(Integer, primary_key=True, index=True) text = Column(String, index=True) metadata_ = Column(JSON, index=True) node_id = Column(String, unique=True, index=True) embedding = Column(Vector(1024)) owner_id = Column(Integer, ForeignKey("users.id")) owner = relationship("User", back_populates="files")
text_store = LanceDBVectorStore(uri="lancedb", table_name="text_collection") image_store = LanceDBVectorStore(uri="lancedb", table_name="image_collection") storage_context = StorageContext.from_defaults( vector_store=text_store, image_store=image_store ) index = MultiModalVectorStoreIndex.from_vector_store( vector_store=text_store, embed_model=HuggingFaceEmbedding(model_name="BAAI/bge-large-en-v1.5"), # dim = 1024 image_vector_store=image_store, image_embed_model=ClipEmbedding(model_name="ViT-L/14") # dim = 768 ) retriever_engine = index.as_retriever( similarity_top_k=2, image_similarity_top_k=2 )
ValueError: Query vector size 1024 does not match index column size 768
use_async=True
return errors. Am I doing anything wrong? Here is the example error when I use SubQuestionQueryEngine
:File "/opt/anaconda3/envs/talking-resume/lib/python3.11/site-packages/llama_index/core/async_utils.py", line 49, in run_async_tasks outputs: List[Any] = asyncio.run(_gather()) ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/talking-resume/lib/python3.11/asyncio/runners.py", line 186, in run raise RuntimeError( RuntimeError: asyncio.run() cannot be called from a running event loop /opt/anaconda3/envs/talking-resume/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py:-1: RuntimeWarning: coroutine 'run_async_tasks.<locals>._gather' was never awaited RuntimeWarning: Enable tracemalloc to get the object allocation traceback /opt/anaconda3/envs/talking-resume/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py:-1: RuntimeWarning: coroutine 'SubQuestionQueryEngine._aquery_subq' was never awaited RuntimeWarning: Enable tracemalloc to get the object allocation traceback