Interface ContentRetriever
- All Known Implementing Classes:
AzureAiSearchContentRetriever, AzureCosmosDBNoSqlContentRetriever, ElasticsearchContentRetriever, EmbeddingStoreContentRetriever, HibernateContentRetriever, SqlDatabaseContentRetriever, WebSearchContentRetriever
public interface ContentRetriever
Retrieves
The goal is to retrieve only relevant
The underlying data source can be virtually anything:
Contents from an underlying data source using a given Query.
The goal is to retrieve only relevant
Contents in relation to a given Query.
The underlying data source can be virtually anything:
- Embedding (vector) store (seeEmbeddingStoreContentRetriever) - Full-text search engine (seeAzureAiSearchContentRetrieverin thelangchain4j-azure-ai-searchmodule) - Hybrid of vector and full-text search (seeAzureAiSearchContentRetrieverin thelangchain4j-azure-ai-searchmodule) - Web Search Engine (seeWebSearchContentRetriever) - Knowledge graph (seeNeo4jContentRetrieverin thelangchain4j-community-neo4j-retrievermodule) - SQL database (seeSqlDatabaseContentRetrieverin thelangchain4j-experimental-sqlmodule) - etc.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault ContentRetrieveraddListener(ContentRetrieverListener listener) Wraps thisContentRetrieverwith a listening retriever that dispatches events to the provided listener.default ContentRetrieveraddListeners(Collection<ContentRetrieverListener> listeners) Wraps thisContentRetrieverwith a listening retriever that dispatches events to the provided listeners.default CompletableFuture<List<Content>> retrieveAsync(Query query) Non-blocking counterpart ofretrieve(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.
-
Method Details
-
retrieve
-
retrieveAsync
Non-blocking counterpart ofretrieve(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.The default implementation returns a failed future carrying
AsyncNotSupportedException: a retriever backed by blocking I/O (embedding-model call, vector-store query, web search, etc.) must opt in by overriding this method so it can return a genuinely non-blocking future instead of secretly tying up a worker thread. A retriever that cannot be made non-blocking is still usable from these modes viaDefaultRetrievalAugmentor, which offloads the blockingretrieve(Query)to its executor.An implementation that honors cancellation should abort its in-flight I/O when the returned future is cancelled (best-effort); Java cannot safely interrupt arbitrary code, so this is not guaranteed.
- Parameters:
query- TheQueryto use for retrieval.- Returns:
- A
CompletableFutureof the retrievedContents, sorted by relevance. - Since:
- 1.20.0
-
addListener
Wraps thisContentRetrieverwith a listening retriever that dispatches events to the provided listener.- Parameters:
listener- The listener to add.- Returns:
- An observing
ContentRetrieverthat will dispatch events to the provided listener. - Since:
- 1.11.0
-
addListeners
Wraps thisContentRetrieverwith a listening retriever that dispatches events to the provided listeners.Listeners are called in the order of iteration.
- Parameters:
listeners- The listeners to add.- Returns:
- An observing
ContentRetrieverthat will dispatch events to the provided listeners. - Since:
- 1.11.0
-