Replies: 2 comments
-
|
The official documentation of Spring AI states that VectorStoreDocumentRetriever allows for direct retrieval from the vector repository. You can create different vector retrievers and merge the results with ConcatenationDocumentJoiner https://docs.spring.io/spring-ai/reference/api/retrieval-augmented-generation.html |
Beta Was this translation helpful? Give feedback.
-
|
Hey @marcelodl , I ran into the exact same problem while building a multi-domain RAG service where I needed to query activity data, nutrition data, and Approach 1: Manual retrieval + prompt template variables (Recommended) This gives you full control over each query's filters and topK, and lets you place each context exactly where you want in the prompt. // 1. Run separate vector store queries with different filters SearchRequest nutritionSearch = SearchRequest.builder() List activityDocs = vectorStore.similaritySearch(activitySearch); // 2. Format each context String nutritionContext = nutritionDocs.stream() // 3. Inject both into the prompt as separate variables This approach is clean and gives you full control — you decide the filter, topK, and exact placement of each context block in the prompt. Approach 2: Using RetrievalAugmentationAdvisor with multiple retrievers As @gengzi mentioned, Spring AI's newer RAG API provides VectorStoreDocumentRetriever and ConcatenationDocumentJoiner for this exact use case: DocumentRetriever activityRetriever = VectorStoreDocumentRetriever.builder() DocumentRetriever nutritionRetriever = VectorStoreDocumentRetriever.builder() RetrievalAugmentationAdvisor advisor = RetrievalAugmentationAdvisor.builder() String response = chatClient.prompt() This merges all retrieved documents into a single context block automatically. It's cleaner if you don't need separate placement of each context in the For your use case where you explicitly want and as separate sections, its better to go with Approach 1. It's more code but gives you precise control over how each context appears in the prompt. Hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone, I need some guidance.
I’m using a
vectorStoreand want to build a prompt that includes two distinct contexts, both retrieved from the vector store, for example:I’m currently using
QuestionAnswerAdvisorylike this:What’s the recommended Spring AI pattern to run two separate vectorStore queries (with different filters/topK) and inject both result sets into a single prompt?
<context1>and<context2>) viaprompt().param(...)?Any code snippet or best practice for merging multiple retrievals into one prompt would be greatly appreciated. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions