haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Add top_k parameter to ChatMessageRetriever

Open Emil-io opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. The ChatMessageRetriever for RAG + Chat always provides the whole conversation history. That way, at some point the context window is exceeded.

Describe the solution you'd like Something similar to a top_k parameter in the init of the component. That way, only a specified number of the latest chat messages is retrieved. This could the also potentially be provided to a summary prompt node, that summarizes multiple ChatMessages.

Describe alternatives you've considered Custom logic, where the last chat messages are stored separately and are concatenated to the query.

Emil-io avatar Aug 20 '24 14:08 Emil-io

can I get this issue?

MetroCat69 avatar Aug 22 '24 07:08 MetroCat69

Thanks for the initiative @MetroCat69 Sure, please feel free to create a draft pull request early on so that we can give feedback.

julian-risch avatar Aug 23 '24 09:08 julian-risch

What's the proper name here top_k, last_k or something else cc @TuanaCelik @Emil-io @julian-risch ?

vblagoje avatar Sep 02 '24 13:09 vblagoje

What's the proper name here top_k, last_k or something else cc @TuanaCelik @Emil-io @julian-risch ?

Maybe last_k, so that people do not think it also filters down to the best matching text messages? Also it better describes what this parameter is doing, but this is just my opinion.

Emil-io avatar Sep 02 '24 16:09 Emil-io

Yeah, good points @Emil-io thank you - I'll update the PR to use last_k as it better clarifies what's going on.

vblagoje avatar Sep 02 '24 17:09 vblagoje

Hmm, but we also then deviate from retriever + top_k usage. Hmm, really not sure how to name this one. @TuanaCelik @julian-risch ?

vblagoje avatar Sep 02 '24 17:09 vblagoje

I think we are making a mistake by calling this a retriever and this conversation made me come to this conclusion.

A retriever has too much connotation for something that will be retrieving based on similarity, embedding, etc. In which case top_k makes sense. However, my understanding from the ChatMessageRetriever is that it simply fetches all of the messages in the store right? Would we have any use case where this retriever would be used to retrieve 'relevant messages' based on a similarity metirc? In which case, I think having both top_k and last_k may make sense but I'm a bit worried this mixes up concepts too much.

TLDR: I don't think we should use top_k to do something that is not actual 'top k'...

@anakin87 - What's your take on this?

TuanaCelik avatar Sep 04 '24 13:09 TuanaCelik

I'm just commenting on the best name to give to this parameter (not the component name).

I think something like last_k, last_k_messages, or last_n_messages might work...

anakin87 avatar Sep 04 '24 13:09 anakin87

last_k it is, we can add top_k later when these become searching retrievers.

vblagoje avatar Sep 04 '24 14:09 vblagoje