← Portfolio/free-code

free-code

RAG — a local knowledge base your agent can search.

What is RAG?

Retrieval-Augmented Generation — give the agent your own documents as searchable context.

RAG lets free-code answer from your material — docs, runbooks, ADRs, API references, a third-party library's manual — instead of guessing. You index documents once; during a session the agent retrieves the most relevant passages and grounds its answer in them (and can cite the source) rather than hallucinating.

Everything runs locally: a small server on your machine, a local embedding model, and an on-disk vector index. Nothing is uploaded to the cloud.

Watch: RAG in free-code

See the local knowledge base indexed and queried end to end.

How it works

Model, database, and how matches are found.

PieceWhat free-code uses
Embedding modelall-MiniLM-L6-v2 (sentence-transformers), runs locally — 384-dimension vectors
Vector databaseFAISS (IndexFlatL2), persisted on disk under ~/.free-code/faiss_store/ (faiss.index + metadata.pkl)
ChunkingRecursive splitter — ~1000 chars per chunk with 200 char overlap, split on paragraphs → lines → words
ServerLocal HTTP server on http://localhost:8085

Indexing (once per document)

  1. The file is loaded and split into overlapping chunks.
  2. Each chunk is turned into a 384-dimension vector by the embedding model.
  3. Vectors + metadata (source file, text) are stored in the FAISS index for the active knowledge base.

Searching & matching

  1. Your query is embedded with the same model, into the same vector space.
  2. FAISS finds the nearest chunk vectors by L2 (Euclidean) distance — smaller distance means more semantically similar (it matches by meaning, not keywords).
  3. The closest top 5 chunks are returned, and results past a distance threshold (~1.2) are dropped so weak matches don't add noise.
  4. The surviving chunks are injected into the conversation as context for the model to answer from.
Semantic, not literal
Because matching is on embeddings, a query like "how do we authenticate users?" can match a chunk that talks about "login flow" or "session tokens" even without sharing the same words.

Flow diagrams

Two pipelines: putting documents in, and querying them back out.

1 · Indexing — putting information in

Document .md · .pdf · .docx Chunk ~1000 chars, 200 overlap Embed MiniLM-L6-v2 · 384-d Store in FAISS vectors + metadata
Runs once per document (/rag addFile, /rag addGroup, /rag addGithubUrl). Everything is stored locally under ~/.free-code/faiss_store/ for the active knowledge base.

2 · Querying — getting information back out

Your query /rag search "…" Embed query same model / space FAISS search nearest by L2 Top 5 drop dist > ~1.2 Inject context agent answers
The query and the documents are embedded by the same model into the same 384-d space — that's why matching is by meaning, not keywords. Weak matches beyond the threshold are dropped so they don't add noise.

Supported file types

Index plain text and common document formats.

TypeExtensions
Plain text.txt
Markdown.md
PDF.pdf
Word.docx, .doc
Optional metadata sidecar
Place a <name>.knowledge.md next to a document to attach extra notes/description for that source. It is used as discovery metadata and excluded from normal search chunks.

Using it — commands

Start the server, create a knowledge base, add documents, and search.

Start the server

# Keep this running (default http://localhost:8085)
free-code-rag

Quick start in a session

/rag-kb create my-docs     # create a knowledge base
/rag-kb use my-docs        # make it the active one
/rag addFile ./README.md   # index a document
/rag search "how does auth work?"   # query it

Documents

CommandDescription
/rag addFile <path>Index a single document
/rag addGroup <folder>Index all supported files in a folder
/rag addGithubUrl <url> [subpath]Clone a GitHub repo and index its files (saved as a source for refreshes)
/rag search <query>Query the active knowledge base and inject the matches as context
/rag listList indexed documents
/rag remove <file>Remove a document from the index
/rag refreshRe-fetch and re-index registered sources
/rag schedule [daily|weekly]Automatic recurring refresh (needs a GitHub source)

Knowledge bases

CommandDescription
/rag-kb create <name>Create a named knowledge base
/rag-kb use <name>Switch the active knowledge base
/rag-kb listList all knowledge bases

Why multiple knowledge bases

Separate indexes you switch between with /rag-kb use.

Each knowledge base is its own isolated index. Keeping several — instead of one big pile — pays off:

  • Sharper results — searching a focused KB returns more on-topic matches; unrelated documents can't crowd out the right ones.
  • Per-project / per-domain context — one KB for your backend, one for the design system, one for a client's docs. Switch with /rag-kb use.
  • No cross-contamination — confidential or client-specific material stays in its own KB and never leaks into another project's answers.
  • Cheaper, faster — a smaller, relevant index means quicker search and tighter, lower-token context.
  • Easy lifecycle — refresh, rebuild, or drop a whole topic by managing just its KB.
Example
/rag-kb use backend-api before working on the service, then /rag-kb use design-system when you switch to the UI — the agent always retrieves from the right body of knowledge.