Get total number of results in the response

Is there a way to actually know the total number of matched documents to my query without fetching the whole result set?

For example, if I set the limit to 10, how do I know the total number of matched results so I can implement pagination from the client side?

Also the limit is implemented on document parts, so I’m getting 10 document parts and unknown number of documents in the response, is there way to make the limit on the documents instead of parts?

1 Like

Hi hossam,

Is there a way to actually know the total number of matched documents to my query without fetching the whole result set?

Unfortunately not. The reason is that in the neural retrieval world where vector matching is carried out, all documents (document parts) are a match. It is just that some have lower similar score (not zero) and some have higher. This is different than the old world of keyword-based search where if a document does not contain words from the query, the document is not a match (score zero).

One suggestion I have for you is to look at the cutoff field in the reranker configuration in the query api (Advanced Single Corpus Query | Vectara Docs). With the cutoff, you can define what’s the lowest similarity score you are interested in. Then, the search may not return all docs (doc parts) if they aren’t relevant.

Also the limit is implemented on document parts, so I’m getting 10 document parts and unknown number of documents in the response, is there way to make the limit on the documents instead of parts?

We do not support limiting results by document instead of document parts. The main reason is the in general, documents are large and contain varying information. Some parts of the document might be excellent match, while others are not. So ordering the results, especially when feeding to the LLM, can be come problematic. Though I will relay your request to our product team to look at supporting this if possible (cannot say when).

Thanks.