Find answers from the community

Home
Members
sti_uuuuu_its
s
sti_uuuuu_its
Offline, last seen 3 months ago
Joined September 25, 2024
Hi, I'm using 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:

Plain Text
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]
)


However, the SelectionOutputParser.parse automatically append a FORMAT_STR like this prompt_template + "\n\n" + _escape_curly_braces(FORMAT_STR) which results in:

Plain Text
### 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>"
    }},
    ...
]

How can I move the ### Assistant: to right after the FORMAT_STR?
14 comments
s
L
Hi, I have multiple documents that uploaded by a user, then I persist them in a S3 storage. As I know it would be OK to persist indices in the same 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.
I'm thinking about create a folder for each document, like {s3_bucket}/{doc_id}, maybe it will work. Although, in loading state, I have to use a loop to load all documents' index.

Is it the correct way to handle such situation? Do you guys have any suggestion for improvement? Thanks in advance.
13 comments
L
s
Hi, I see there is SubQuestionQueryEngine , is there anything with the same function for ContextChatEngine? Thanks in advance.
8 comments
s
L
Hi , what do the files 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.
3 comments
W
s
Hi everyone, I want to create a new 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:
Plain Text
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")

How can I do that? I'm trying to create a new sqlalchemy model but don't know how to make PGVectorStore uses this instead of the default model.
Plain Text
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")

Thanks in advance.
5 comments
s
L
Hi, I'm trying to do multi-modal RAG like this:

Plain Text
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
)

But when I do retrieval, it raises ValueError: Query vector size 1024 does not match index column size 768

How can I modify the dimension for each vector store? I can't find the args for that. Thanks in advance.
11 comments
s
L
Hi, I'm using LlamaIndex 0.10.18 with FastAPI. Every module that I use with use_async=True return errors. Am I doing anything wrong? Here is the example error when I use SubQuestionQueryEngine:

Plain Text
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
6 comments
L
s