Find answers from the community

Updated last year

How do i limit query response or define the output size.

@kapa.ai How do i limit query response or define the output size.
k
2 comments
Please stand by @LoLiPoPMaN as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
In LlamaIndex, you can limit the query response or define the output size by specifying options in your index query.

For instance, you can use the similarity_top_k option to fetch the top K closest matching terms/definitions to the query. If you set similarity_top_k=5, the index will fetch the top 5 closest matching terms/definitions to the query.

Additionally, you can use the response_mode option to control the amount of text from the matching terms/definitions used in each LLM call. If you set response_mode="compact", as much text as possible from the 5 matching terms/definitions will be used in each LLM call. Without this, the index would make at least 5 calls to the LLM, which can slow things down for the user.

Here is an example of how you might specify these options in your code:

Plain Text
query_engine = index.as_query_engine(similarity_top_k=5, response_mode="compact")
response = query_engine.query("Your query here")


Please note that the above code is a hypothetical example and may not work as-is. You should adjust it according to your specific needs and the actual API of LlamaIndex.

For more details, you can refer to the LlamaIndex documentation ().
----------------------
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