Class WebSearchContentRetriever
java.lang.Object
dev.langchain4j.rag.content.retriever.WebSearchContentRetriever
- All Implemented Interfaces:
ContentRetriever
A
It returns one
Depending on the
ContentRetriever that retrieves relevant Content from the web using a WebSearchEngine.
It returns one
Content for each result that a WebSearchEngine has returned for a given Query.
Depending on the
WebSearchEngine implementation, the Content.textSegment()
can contain either a snippet of a web page or a complete content of a web page.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
ConstructorsConstructorDescriptionWebSearchContentRetriever(WebSearchEngine webSearchEngine, Integer maxResults) -
Method Summary
Modifier and TypeMethodDescriptionbuilder()retrieveAsync(Query query) Non-blocking counterpart ofContentRetriever.retrieve(Query), invoked by the asynchronous (CompletableFuture/CompletionStage) and reactive (Flow.Publisher) AI Service modes when RAG is configured.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ContentRetriever
addListener, addListeners
-
Constructor Details
-
WebSearchContentRetriever
-
-
Method Details
-
builder
-
retrieve
Description copied from interface:ContentRetrieverRetrieves relevantContents using a givenQuery. TheContents are sorted by relevance, with the most relevantContents appearing at the beginning of the returnedList<Content>.- Specified by:
retrievein interfaceContentRetriever- Parameters:
query- TheQueryto use for retrieval.- Returns:
- A list of retrieved
Contents.
-
retrieveAsync
Description copied from interface:ContentRetrieverNon-blocking counterpart ofContentRetriever.retrieve(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 blockingContentRetriever.retrieve(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.
- Specified by:
retrieveAsyncin interfaceContentRetriever- Parameters:
query- TheQueryto use for retrieval.- Returns:
- A
CompletableFutureof the retrievedContents, sorted by relevance.
-