Spring / Spring AI interview questions
What is the SearchRequest API in Spring AI's VectorStore?
SearchRequest is the query object you pass to VectorStore.similaritySearch(). It encapsulates the query string plus optional filters — maximum results, similarity threshold, and metadata filter expressions — so you can constrain what documents come back rather than retrieving everything above some similarity floor.
// Basic: top-5 most similar documents
List<Document> docs = vectorStore.similaritySearch(
SearchRequest.query(userQuestion).withTopK(5));
// With similarity threshold — only return docs scoring above 0.75
List<Document> precise = vectorStore.similaritySearch(
SearchRequest.query(userQuestion)
.withTopK(5)
.withSimilarityThreshold(0.75));
// With metadata filter — only search documents from a specific source
Filter.Expression filter = new Filter.ExpressionBuilder()
.eq("source", "spring-ai-docs.pdf")
.build();
List<Document> filtered = vectorStore.similaritySearch(
SearchRequest.query(userQuestion)
.withTopK(5)
.withFilterExpression(filter));The metadata filter uses an expression builder API that is translated by each VectorStore implementation into its native query language — SQL WHERE clause for PgVector, Redis filter syntax for Redis, Pinecone metadata filter JSON, etc. This means your filter logic is portable and does not leak provider-specific syntax into application code.
Tuning topK and similarityThreshold is a key RAG quality lever. Returning too many low-relevance documents bloats the prompt and can confuse the model; returning too few may miss critical context.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
