Find answers from the community

Updated 2 years ago

Top k chunks

Hello all,
Is there a way to print only the top k chunks based on user query using llama index?

As far as my understanding, llama index creates an embedding of the user query and finds the top most similar <similarity_top_k> chunks (using cosine similarity). Is there a way to print what these top k chunks are?
1
L
m
i
8 comments
You can access them in the response object

response.source_nodes
This gives the required answer.
But, I don't want to query LLM to get response. I only need the most similar chunks. Is there any way to get that without doing - response = index.query(*)
I have the same question
I'm also trying to achieve the same.
@Logan M any help would be appreciated. Thanks.
@mathada @swapnil3597 @idea&steps

You can set the response mode so that only the source nodes are fetched, no LLM calls

index.query(..., response_mode="no_text")

If you get an error, upgrade to the latest version, there was a recent bug πŸ›
Thanks @Logan M
Hii @Logan M,
I have observed that the chunks which we receive using "response.source_nodes" have incomplete sentences. It ends abruptly.
Right. With default settings, documents are chunked into a default chunk size of 3900 tokens. The default overlap of these nodes is 200 tokens.

You can also try to use a different text splitter (like a sentence text splitter)
Add a reply
Sign up and join the conversation on Discord