Class VectorStoreDocumentRetriever

java.lang.Object
org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever
All Implemented Interfaces:
Function<Query,List<Document>>, DocumentRetriever

public final class VectorStoreDocumentRetriever extends Object implements DocumentRetriever
Retrieves documents from a vector store that are semantically similar to the input query. It supports filtering based on metadata, similarity threshold, and top-k results.

Example usage:


 VectorStoreDocumentRetriever retriever = VectorStoreDocumentRetriever.builder()
     .vectorStore(vectorStore)
     .similarityThreshold(0.73)
     .topK(5)
     .filterExpression(filterExpression)
     .build();
 List<Document> documents = retriever.retrieve(new Query("example query"));
 

The FILTER_EXPRESSION context key can be used to provide a filter expression for a specific query. This key accepts either a string representation of a filter expression or a Filter.Expression object directly.

Since:
1.0.0
Author:
Thomas Vitale