Find answers from the community

Home
Members
Stéphane
S
Stéphane
Offline, last seen 4 months ago
Joined September 25, 2024
I have a function that finds the real id of a node from a custom id I added in the metadata when loading the documents:

def get_real_node_id_from_custom_id(custom_id, index): for node in index.docstore.docs.values(): if node.metadata.get('custom_id') == custom_id: return node.id_ return None

This works fine when I use the default llamaindex vector store, but not when I use chromadb. The only difference in my code is how I create the storage context:

if my_vector_store == "default": storage_context = StorageContext.from_defaults() elif my_vector_store == "chromadb": chroma_client = chromadb.PersistentClient(path="./storage") chroma_collection = chroma_client.create_collection("quickstart") vector_store = ChromaVectorStore(chroma_collection=chroma_collection) storage_context = StorageContext.from_defaults(vector_store=vector_store)

When using chromadb, it looks like index.docstore.docs is an empty {}.
How can I search my index for a specific metadata value when the vector store is chromadb?
3 comments
L
W
Hi, I would like to test the effect of varying different parameters in my RAG app (embed model, reranker, etc...) on the retrieval performance. Specifically, I would like to input a dictionary of pairs of user queries and associated correct node ids (where the answer to the query can be found), and then compute the % of times a set of parameters finds the correct node in top place. Does llamaindex offer an easy way to do such benchmarking? I haven’t seen that in the doc, but I prefer to be sure before coding this from scratch. 🙂 thanks.
1 comment
T
Simple question, but can’t find the answer, how do I access the text of the first node retrieved? Something like
response.source_nodes[0].node.text
but this gives error "object is not subscriptable"
2 comments
d
W
I am trying to replicate the PandasQueryEngine example from the docs (with non-default LLMs and embeddings, if it matters):

Plain Text
import pandas as pd
from llama_index.query_engine import PandasQueryEngine
# Test on some sample data
df = pd.DataFrame(
    {
        "city": ["Toronto", "Tokyo", "Berlin"],
        "population": [2930000, 13960000, 3645000],
    }
)
query_engine = PandasQueryEngine(df=df, verbose=True)
response = query_engine.query(
    "What is the city with the highest population?",
)


but I keep getting an error

Plain Text
> Pandas Instructions:

 df['city'][df['population'].idxmax()]
Traceback (most recent call last):
  File "C:\Users\Stephane\miniconda3\envs\llamaindex\lib\site-packages\llama_index\query_engine\pandas_query_engine.py", line 61, in default_output_processor
    tree = ast.parse(output)
  File "C:\Users\Stephane\miniconda3\envs\llamaindex\lib\ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 2
    df['city'][df['population'].idxmax()]
IndentationError: unexpected indent
> Pandas Output: There was an error running the output as Python code. Error message: unexpected indent (<unknown>, line 2)


Any idea why?
Side-question: is PandasQueryEngine the best way to build a RAG app when the information is to be found in a table?
4 comments
L
W
S
S
Stéphane
·

Refine

Hi, I’m trying to understand prompts and the refine_template in particular. Reading the doc page here https://docs.llamaindex.ai/en/stable/examples/prompts/prompts_rag.html I can see there is a "new context" field in the refine_template. But there is no mention of where this new context is coming from. What is the default and how do we change it?
2 comments
S
L
Second question : in order to correct wrong answers or "I don’t know" answers, I would like to allow my users to enter the correct response in a streamlit text area:

Plain Text
correction = st.text_area("A mistake ? Correct me here.")
  correct_button=st.button('Send')
  if (correct_button==True):
      new_document = Document(
          text=correction,
          metadata={"correction": "True"},
      )
      index.insert(document = new_document)
      index.storage_context.persist()
      query_engine = index.as_query_engine()


This code snippet doesn’t seem to work though. The index is updated, I can see the new document in it. But the chatbot keeps saying it doesn’t know the answer to the question.
1 comment
L
Hi, is there a parameter in the response from a query_engine that would allow me to know if the LLM has decided that the answer was present in the context? I would like to display the source nodes used to answer the query but only if the answer to this query was found in the context.
5 comments
L
S
W
Hi everyone,
I am building a RAG app where I want the user to be able to select the files she wants to query (using the streamlit "multiselect" widget).
I am unsure what is the best way to implement that. My first idea was to create an index for each file, and then load and merge the indices as necessary. But it seems Llamaindex is not great at merging indices? I have seen the solution 'index = GPTListIndex([index1, index2])' is mentioned multiple times in the Github help section but it’s not working for me (it should receive nodes as inputs and not indices if I’m not mistaken). I have also seen the possibility to use the index.insert() and delete_ref_doc() function, but I’m not sure how to keep track of all the ids of my documents.

I’m also open to other solutions using only one index (and filtering nodes with a "tag" metadata, using graphs...)
4 comments
L
S
W
Hi everyone, I am running my app on a server only partly connected to the internet, for data privacy reasons. The app works, but when I run it, I get this error message:

[nltk_data] Error loading punkt: <urlopen error [WinError 10054] An
[nltk_data] existing connection was forcibly closed by the remote
[nltk_data] host>

This error is thrown when the ServiceContext.from_defaults() function is executed. I think this is because my company is blocking some connections to some websites. But I have two questions:

  • is it normal behavior that nltk is reached at the moment of the execution of the script? Shouldn’t everything be installed when I do "pip install"?
  • any way to make this error disappear and have my script run fully locally, without calling any url at the moment of execution?
Thanks!
2 comments
L
W
S
Stéphane
·

Hi there,

Hi there,
I’m using a local embedding model and Azure open AI for the response synthesis. I’m getting response times of about 10s as measured by:

Plain Text
start_time = time.time()
response = query_engine.query(question)
response_time = time.time()-start_time


Is it possible to get execution times of what happens inside this (black for me) box query_engine.query()? I need to know if the 10s are mostly due to azure open AI (and thus I can’t do anything about it) or if they are coming from the local embedding on my machine.

For instance, does OpenAI return the time it took to create a response on its server?
8 comments
j
S
L
W
T
I’m trying to generate questions/answers pairs from a document. In the documentation here https://github.com/run-llama/llama_index/blob/3823389e3f91cab47b72e2cc2814826db9f98e32/llama-index-core/llama_index/core/llama_dataset/generator.py#L236 there is both a

async def agenerate_dataset_from_nodes(self) -> LabelledRagDataset: """Generates questions for each document.""" return await self._agenerate_dataset(self.nodes, labelled=True)

function and a

def generate_dataset_from_nodes(self) -> LabelledRagDataset: """Generates questions for each document.""" return asyncio.run(self.agenerate_dataset_from_nodes())

function. Shouldn’t this second function not be run asynchronously? I was trying to generate questions/answers in a non-asynchronously way but kept running into an error "sys:1: RuntimeWarning: coroutine 'RagDatasetGenerator.agenerate_dataset_from_nodes' was never awaited" which is coming from this function I think.
1 comment
L