DeepReach
GenAI14 interview questions

RAG Pipelines with Spring AI and Vector Stores

Build production-grade RAG systems using Spring AI. Covers chunking strategies, embedding models, vector store selection, and retrieval tuning.

RAGSpring AIEmbeddingsVector DB

RAG Pipelines with Spring AI and Vector Stores

RAG Architecture

Retrieval-Augmented Generation (RAG) enhances LLM responses with relevant context from your data:

Query → Embed Query → Vector Search → Retrieve Chunks → Augment Prompt → LLM → Response

Spring AI Setup

xml
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency>

Document Ingestion Pipeline

java
@Service
public class DocumentIngestionService {
    private final VectorStore vectorStore;
    private final TokenTextSplitter splitter = new TokenTextSplitter(512, 128);

    public void ingest(Resource resource) {
        var reader = new PdfDocumentReaderConfig.Builder()
            .withPagesPerDocument(1)
            .build();

        List<Document> docs = new PagePdfDocumentReader(resource, reader).get();
        List<Document> chunks = splitter.apply(docs);
        vectorStore.add(chunks);
    }
}

Retrieval and Augmentation

java
@Service
public class RagService {
    private final VectorStore vectorStore;
    private final ChatClient chatClient;

    public String query(String question) {
        List<Document> relevant = vectorStore.similaritySearch(
            SearchRequest.query(question).withTopK(5).withSimilarityThreshold(0.75)
        );

        return chatClient.prompt()
            .advisors(new QuestionAnswerAdvisor(vectorStore, SearchRequest.defaults()))
            .user(question)
            .call()
            .content();
    }
}

Interview Questions

  1. 1.How do you choose chunk size for your domain?
  2. 2.What is the difference between semantic search and keyword search?
  3. 3.How do you evaluate RAG pipeline quality?
  4. 4.What is hybrid search and when should you use it?
  5. 5.How do you handle document updates in a vector store?