Build a mini knowledge base from local docs

Now you know why you need retrieval and which tools to use — let’s build a simple knowledge base (KB) your assistant can search in real time.

A mini KB means:

  • A small collection of your own files (PDFs, text, markdown, or notes).

  • Chunked into passages.

  • Embedded as vectors for similarity search.

This is the heart of Retrieval-Augmented Generation (RAG).


Step 1️⃣ – Gather Local Files

Decide what your assistant should know:

  • Help docs

  • Study notes

  • Internal FAQs

  • Markdown files

  • Local PDFs

👉 Example: docs/ folder with:

docs/
 ├─ faq.txt
 ├─ guide.md
 ├─ product_manual.pdf

Step 2️⃣ – Load & Chunk Text

Use Python to read your files and split them into small, meaningful chunks (~100–300 words each) — so they fit inside the LLM’s context window.

Example:

👉 Tip: For PDFs, use PyMuPDF or pdfminer:

Example:


Step 3️⃣ – Embed Each Chunk

Turn each text chunk into a vector using a sentence embedding model.

Example with sentence-transformers:


Step 4️⃣ – Store in FAISS

Save these vectors in a FAISS index for fast retrieval.


Step 5️⃣ – Query Your Knowledge Base

When a user asks a question: 1️⃣ Embed the query ➜ 2️⃣ Find top N chunks ➜ 3️⃣ Pass them + the query to your LLM.

Example:


How It Works Together

✅ Now your assistant:

  • Embeds user questions

  • Finds relevant info from your local docs

  • Adds that info to the prompt

  • Generates grounded, up-to-date answers


🗝️ Key Takeaway

This mini knowledge base gives your assistant a custom memory of your own files — bridging the gap between the frozen base LLM and your real-world needs.


➡️ Next: You’ll learn how to connect this retrieval step to your chat interface — so your assistant can quote relevant info on demand!

Last updated