Skip to content

feat(rag): RAG v0 — docs corpus retrieval, agon rag CLI, ProjectConte…#210

Merged
cukas merged 2 commits into
mainfrom
feat/rag-v0
Jun 12, 2026
Merged

feat(rag): RAG v0 — docs corpus retrieval, agon rag CLI, ProjectConte…#210
cukas merged 2 commits into
mainfrom
feat/rag-v0

Conversation

@cukas

@cukas cukas commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

…xt MCP tool

First shippable RAG slice (6-engine brainstorm design, label rag-first-slice): docs-only corpus (root *.md + docs/) → markdown-aware chunking (heading boundaries, fenced code atomic, ~512tok + 64 overlap) → offline MiniLM embeddings via the new @kernlang/agon-dedup embedder.py sidecar (L2-normalized, persistent model cache under ~/.agon/cache/fastembed) → per-repo persistent index .agon/rag// (manifest + chunks.jsonl + Float32 embeddings.bin, corpus-hash reuse short-circuit) → cosine top-k → fail-closed grounding with [n] source Lx-y citations.

Surfaces:

  • agon rag index|query|stats (citty action dispatch; --json, --force)
  • ProjectContext MCP tool (cited blocks + grounded flag; ungrounded queries return NO context text — never dressed-up weak hits)

All new logic in KERN (core/src/kern/rag/, mcp project-context.kern, cli commands/rag.kern); thin TS facades only. 14 unit tests (chunker fence-atomicity, retriever floor, grounding fail-closed, store round-trip, mocked sidecar boundary).

Review-pass fixes (agon review: codex blocking + important; agy clean):

  • ProjectContext no longer accepts an arbitrary root — an MCP client could point the retriever (reads docs, WRITES .agon/rag/) outside the repo boundary; tool now serves the server cwd only
  • queryRag reloads with the corpus hash the build actually produced, closing the hash-drift TOCTOU between hashCorpus and buildRagIndex

KERN-GAP filed: doc text containing */ breaks the emitted JSDoc block (corpus.kern).

Deferred (AGON.md ## RAG Roadmap): --ground Cesar wire-up, session corpus, review grounding, network exposure, live reindex, hybrid search, federation, citation UX.

Verified live: index 6 files → 118 chunks 1.6s cold / 21ms warm; grounded query cites AGON.md L16-27 (0.63); off-topic fail-closed; MCP tool over real JSONRPC stdio. Gate: kern check clean ×6, build green, 2938/2938 tests.

⚔️ Forged by Agon

…xt MCP tool

First shippable RAG slice (6-engine brainstorm design, label
rag-first-slice): docs-only corpus (root *.md + docs/) → markdown-aware
chunking (heading boundaries, fenced code atomic, ~512tok + 64
overlap) → offline MiniLM embeddings via the new @kernlang/agon-dedup
embedder.py sidecar (L2-normalized, persistent model cache under
~/.agon/cache/fastembed) → per-repo persistent index
.agon/rag/<corpus-hash>/ (manifest + chunks.jsonl + Float32
embeddings.bin, corpus-hash reuse short-circuit) → cosine top-k →
fail-closed grounding with [n] source Lx-y citations.

Surfaces:
- agon rag index|query|stats (citty action dispatch; --json, --force)
- ProjectContext MCP tool (cited blocks + grounded flag; ungrounded
  queries return NO context text — never dressed-up weak hits)

All new logic in KERN (core/src/kern/rag/, mcp project-context.kern,
cli commands/rag.kern); thin TS facades only. 14 unit tests (chunker
fence-atomicity, retriever floor, grounding fail-closed, store
round-trip, mocked sidecar boundary).

Review-pass fixes (agon review: codex blocking + important; agy clean):
- ProjectContext no longer accepts an arbitrary root — an MCP client
  could point the retriever (reads docs, WRITES .agon/rag/) outside the
  repo boundary; tool now serves the server cwd only
- queryRag reloads with the corpus hash the build actually produced,
  closing the hash-drift TOCTOU between hashCorpus and buildRagIndex

KERN-GAP filed: doc text containing */ breaks the emitted JSDoc block
(corpus.kern).

Deferred (AGON.md ## RAG Roadmap): --ground Cesar wire-up, session
corpus, review grounding, network exposure, live reindex, hybrid
search, federation, citation UX.

Verified live: index 6 files → 118 chunks 1.6s cold / 21ms warm;
grounded query cites AGON.md L16-27 (0.63); off-topic fail-closed;
MCP tool over real JSONRPC stdio. Gate: kern check clean ×6, build
green, 2938/2938 tests.

⚔️ Forged by [Agon](https://github.com/KERNlang/agon)

Co-Authored-By: agon (KERN) <292465531+KERN-Agon@users.noreply.github.com>
…hFile)

sidecar.py / classifier.py / history-search.py still used fastembed's
default tmpdir cache; macOS pruned the model snapshot and every bid-dedup
pass crashed with onnxruntime NO_SUCHFILE (seen live in brainstorm
cesar-mode-rag). Apply the same ~/.agon/cache/fastembed pinning that
embedder.py shipped with.

⚔️ Forged by [Agon](https://github.com/KERNlang/agon)

Co-Authored-By: agon (KERN) <292465531+KERN-Agon@users.noreply.github.com>
@cukas cukas merged commit 96e1452 into main Jun 12, 2026
2 checks passed
@cukas cukas deleted the feat/rag-v0 branch June 12, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants