{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreihn5bgjhhbkhyi5z4dd3fef7s3mne4oxeuu2yxu5a6rtzooaqfvfi",
    "uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mpktkdvxtp62"
  },
  "coverImage": {
    "$type": "blob",
    "ref": {
      "$link": "bafkreibz4mon2axlq7276jlomqsrkzoc2htpkee3kauxxat6gpxkgmknn4"
    },
    "mimeType": "image/webp",
    "size": 69208
  },
  "path": "/alkademy/rag-with-spring-boot-embeddings-and-vector-search-step-by-step-2026-5fpk",
  "publishedAt": "2026-07-01T05:39:46.000Z",
  "site": "https://dev.to",
  "tags": [
    "springboot",
    "angular",
    "ai",
    "tutorial",
    "munonye.com",
    "GitHub",
    "AI Developer Tutorials",
    "M7-A Spring AI REST basics",
    "M8-B — Structured JSON from LLMs in Angular",
    "RAG with Spring Boot — Embeddings and Vector Search Step by Step (2026)",
    "LinkedIn",
    "About",
    "@Service",
    "@Value",
    "@PostMapping",
    "@RequestBody"
  ],
  "textContent": "> **Canonical URL:** Republished from munonye.com. Full code on GitHub.\n\nLearn **how to build a RAG Spring Boot tutorial** pipeline that answers questions from your own documents. This post extends the AI Developer Tutorials series and connects to M7-A Spring AI REST basics.\n\n##  RAG architecture\n\n\n    Documents → chunk → embed → VectorStore\n    User question → embed → top-K similar chunks → prompt → LLM → answer\n\n\n##  Dependencies\n\n\n    <dependency>\n      <groupId>org.springframework.ai</groupId>\n      <artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>\n    </dependency>\n    <dependency>\n      <groupId>org.springframework.ai</groupId>\n      <artifactId>spring-ai-openai-spring-boot-starter</artifactId>\n    </dependency>\n\n\n##  Ingestion service\n\n\n    @Service\n    public class DocumentIngestionService {\n      private final VectorStore vectorStore;\n      private final Resource docsFolder;\n\n      public DocumentIngestionService(VectorStore vectorStore,\n          @Value(\"classpath:docs/\") Resource docsFolder) {\n        this.vectorStore = vectorStore;\n        this.docsFolder = docsFolder;\n      }\n\n      public void ingestAll() throws IOException {\n        for (Resource file : docsFolder.getFile().listFiles()) {\n          String text = Files.readString(file.getFile().toPath());\n          List<Document> chunks = split(text, 800, 100);\n          vectorStore.add(chunks);\n        }\n      }\n\n      private List<Document> split(String text, int size, int overlap) {\n        List<Document> out = new ArrayList<>();\n        for (int i = 0; i < text.length(); i += size - overlap) {\n          out.add(new Document(text.substring(i, Math.min(i + size, text.length()))));\n        }\n        return out;\n      }\n    }\n\n\n##  Question endpoint\n\n\n    @PostMapping(\"/api/ask\")\n    public AnswerResponse ask(@RequestBody QuestionRequest req) {\n      List<Document> similar = vectorStore.similaritySearch(req.question(), 5);\n      String context = similar.stream().map(Document::getContent).collect(Collectors.joining(\"\\n---\\n\"));\n      String answer = chatClient.prompt()\n          .system(\"Answer only from the context below. Say 'I don't know' if not found.\\n\" + context)\n          .user(req.question())\n          .call()\n          .content();\n      return new AnswerResponse(answer);\n    }\n\n\n##  Next: function calling from Angular\n\nM8-B — Structured JSON from LLMs in Angular\n\n**Full tutorial:** RAG with Spring Boot — Embeddings and Vector Search Step by Step (2026)\n\n**Kindson Munonye** — GitHub · LinkedIn · About",
  "title": "RAG with Spring Boot — Embeddings and Vector Search Step by Step (2026)"
}