feat(retrievers)!: Move all retriever config options to RetrieverOptions #248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Continuing the efforts to add full LCEL support to all core components.
In this case, the
Retriever
class didn't allow to pass any options when invoking it.VectorStoreRetriever
only supported config options in the constructor, which forced users to re-create the retriever every time they wanted to change the options.A typical use case that was hard to implement was to do an initial search with a high
scoreThreshold
and then repeat the search with a lowerscoreThreshold
if the first search didn't return any results.Now the
Retriever
classes support defining default options when instantiating them, but you can always override them when invoking the retriever.You can also change the options in a
Runnable
pipeline using the bind method.Migration
Getting a retriever from a vector store
The
asRetriever
method now takes an optionaldefaultOptions
parameter instead of asearchType
.Before:
Now:
Custom retrievers
If you have any custom retrievers, the base retriever class has been renamed from
BaseRetriever
toRetriever
.You can also define a custom retriever options class (that extends from
RetrieverOptions
) if you retriever supports additional configuration options.Before:
Now: