Find answers from the community

Updated 6 months ago

My retriever always returns two nodes even though the top_k is set to 10 nodes. Any ideas

@kapa.ai My retriever always returns two nodes even though the top_k is set to 10 nodes. Any ideas why?
k
n
5 comments
Please stand by @node0 as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
Based on the information provided in the knowledge sources, it seems like the top_k value in your retriever is being overridden and set to 2. This is evident from the logs in the examples provided in the source (), where it states Using top_k: 2.

This could be due to the way your retriever is configured. If you're using the VectorIndexAutoRetriever or a similar retriever, it's possible that the top_k value is being set in the retriever's configuration and not being overridden by your retrieve method call.

Here's an example of how the retriever is configured in one of the knowledge sources:

Plain Text
retriever = VectorIndexAutoRetriever(
    index,
    vector_store_info=vector_store_info,
    llm=llm,
    callback_manager=callback_manager,
    max_top_k=10000,
)


In this example, max_top_k is set to 10000. However, in your case, it seems like top_k is being set to 2 somewhere in your configuration or code.

To resolve this issue, you should check your retriever's configuration and ensure that the top_k value is being set correctly. If you're still facing issues, you might want to check the rest of your code to see if top_k is being overridden somewhere else.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai I solved this by setting similarity_top_k to 10.
Let me check the knowledge base for you. One moment! :books:
----------------------
Great! Setting similarity_top_k to 10 in your retriever configuration is indeed a way to specify the number of most similar nodes you want to retrieve. This parameter is used in the as_retriever method as shown in this source ():

Plain Text
vector_retriever = index.as_retriever(similarity_top_k=10)


In this example, similarity_top_k is set to 10, which means the retriever will return the top 10 most similar nodes. Adjusting this parameter according to your needs will help you get the desired number of results.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord