langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.55k stars 15.52k forks source link

Is The Limit Parameter Used to Retrieve Top_k? #15511

Closed mhendy25 closed 7 months ago

mhendy25 commented 11 months ago

In cookbook 3 for multimodal retrieval, limit = 6 is set while retireving documents but the number of returned documents is always 4, regardless of the asked query or the value of limit. How can I retrieve top_k documents in this code? Specific line is here

dosubot[bot] commented 11 months ago

🤖

Hello @mhendy25 :wave:,

I'm Dosu, a friendly bot here to help you out while we're waiting for a human maintainer! I'm pretty good at assisting with bug finding, answering questions, and even helping new contributors get their bearings. Feel free to ask me anything you need assistance with.

The limit parameter you're referring to in the multimodal retrieval function doesn't seem to control the number of returned documents. Instead, the number of returned documents is determined by the top_k parameter in the AmazonKendraRetriever class, which is set to 3 by default.

To retrieve top_k documents, you can set the top_k parameter to your desired value when initializing the AmazonKendraRetriever class. Here's an example:

retriever = AmazonKendraRetriever(
    index_id="c0806df7-e76b-4bce-9b5c-d5582f6b1a03",
    top_k=10  # Set this to your desired value
)

This will return the top 10 documents instead of the default 3. Please note that the actual number of returned documents may be less than top_k if there are not enough documents that match the query.

As for the exact role of the limit parameter in the multimodal retrieval function, I wasn't able to find a clear answer within the repository. It's possible that it serves a different purpose or it might be a leftover from a previous version of the code. If you have further questions or need more clarification, please provide more details.

You can find more information about the top_k parameter in the AmazonKendraRetriever class in the kendra.py file.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.