Find answers from the community

Updated 2 months ago

Getting retrieved nodes for a given query in chat engine

How I can get the retrieved nodes for a given query in chat engine(https://docs.llamaindex.ai/en/stable/examples/chat_engine/chat_engine_context/). Any hint of the steps invovled is appreciated.
Attachment
image.png
t
W
J
3 comments
Try this

Plain Text
index = VectorStoreIndex.from_vector_store(vector_store=qdrant_vector_storage)
 retriever = VectorIndexRetriever(
  index=index,
  similarity_top_k=150
)
retrived_nodes = retriever.retrieve("your_query")
chat_engine = ContextChatEngine(
  retriever=retriever,
  chat_history=[],
  system_prompt=self.PROMPT_TEMPLATE
)
response = chat_engine.chat("your_query")
This will work but you can get source nodes in the similar way that you were getting in query_engine inchat_engine as well.


https://github.com/run-llama/llama_index/blob/main/llama-index-core%2Fllama_index%2Fcore%2Fchat_engine%2Fcontext.py#L223


So something like this

Plain Text
chat_engine= index.as_chat_engine(...)

response= chat_engine.chat("query")

#print source nodes
print(response.source_nodes)


Source nodes contain all the retrieved nodes
Turns out, all i was looking for this command "print(response.source_nodes)" thanks!
Add a reply
Sign up and join the conversation on Discord