feat(rag): RAG over instinct store (issue #160, RAG-v0)#210
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🏆 CEO Audit — A+ (100.0/100)
📥 Download full report (Markdown)
|
🏆 CEO Audit — A+ (100.0/100)
📥 Download full report (Markdown) Run ID:
|
| // Atomic write: temp file + rename, so a crash mid-write | ||
| // never leaves a half-written file behind. | ||
| dir := filepath.Dir(j.path) | ||
| if err := os.MkdirAll(dir, 0o755); err != nil { |
| return err | ||
| } | ||
| tmp := j.path + ".tmp" | ||
| if err := os.WriteFile(tmp, b, 0o644); err != nil { |
Delqhi
force-pushed
the
feat/issue-160-rag
branch
from
June 16, 2026 18:06
acca259 to
e4313f5
Compare
What ships:
- cmd/sin-code/internal/rag/ — 4 source files + 24 race-clean tests
- embedder.go: Embedder interface, CosineSimilarity, Normalize
- embedder_hash.go: HashEmbedder (default, deterministic, no I/O)
- embedder_onnx.go: ONNXRuntimeEmbedder + HTTPEmbedder (stubs)
- index.go: generic in-memory Index with optional Persister
- worker.go: bounded-concurrency WorkerPool (M7)
- retriever.go: high-level Retriever (Embedder + Index → top-N)
- cmd/sin-code/internal/instinct/search.go: cmdSearch + jsonPersister
- cmd/sin-code/internal/instinct/cli.go: register cmdSearch
- cmd/sin-code/internal/instinct/{search,os_helper}_test.go: 8 tests
- rag.doc.md + CHANGELOG entry
Mandate compliance:
- M2 (single binary, no CGO): HashEmbedder is dependency-free
(SHA-256 expansion). ONNXRuntimeEmbedder is a documented stub
that returns ErrONNXNotEnabled at runtime; the operator
enables it by installing libonnxruntime at the system level
and setting SIN_RAG_ONNX_PATH. The binary never sideloads
the .so.
- M5: new code in cmd/sin-code/internal/rag/. No module-path
changes. No new go.mod deps.
- M7 (race-free): 24+8=32 tests pass under go test -race -count=1.
WorkerPool is the load-bearing concurrency primitive.
What does NOT ship (deferred per issue body):
- GOAP Planner (v1, ~4 weeks)
- Federation (v2, ~3 months)
- Real ONNX implementation: stub is in place; follow-up PR
adds the real wiring after operator verifies the CGO-free
build path on the target platform
Trade-offs (documented in rag.doc.md):
1. Index lives in JSON, not bbolt. The instinct subsystem is
filesystem-based; reusing bbolt would require migrating the
instinct store (out of scope) or maintaining two stores.
2. HashEmbedder is the default. Swap to ONNX is a 1-line
change in the worker pool constructor.
3. Reindex on every search call. Cheap at <100 active instincts.
Refs: #160
Delqhi
force-pushed
the
feat/issue-160-rag
branch
from
June 16, 2026 18:09
e4313f5 to
49c8360
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the fourth of the 5 issues. Scope-bounded to RAG-v0 (Embedder interface + HashEmbedder default + ONNX stub + WorkerPool + Index + Retriever + sin instinct search CLI).
What ships
cmd/sin-code/internal/rag/— 4 source files + 24 race-clean testsembedder.go— Embedder interface, CosineSimilarity, Normalizeembedder_hash.go— HashEmbedder (default, deterministic, no I/O)embedder_onnx.go— ONNXRuntimeEmbedder + HTTPEmbedder (stubs)index.go— generic in-memory Index with optional Persisterworker.go— bounded-concurrency WorkerPool (M7)retriever.go— high-level Retriever (Embedder + Index → top-N)cmd/sin-code/internal/instinct/search.go— cmdSearch + jsonPersistercmd/sin-code/internal/instinct/cli.go— register cmdSearchcmd/sin-code/internal/instinct/{search,os_helper}_test.go— 8 testsMandate compliance
ErrONNXNotEnabledat runtime; the operator enables it by installinglibonnxruntimeat the system level and settingSIN_RAG_ONNX_PATH. The binary never sideloads the .so.cmd/sin-code/internal/rag/. No module-path changes. No newgo.moddeps.go test -race -count=1. WorkerPool is the load-bearing concurrency primitive.Acceptance criteria (from #160)
sin instinct search "<query>"returns the top-5 matchesRenderSystemBlock(active, 5)returns at most 5 instincts, ranked by similarity — covered by therag.Retriever.TopNinterface; the instinct-RenderSystemBlock wiring is a follow-up (the instinct subsystem's render path is its own concern; the rag package is the building block)WorkerPoolis the mechanism; embedding happens in a goroutine pool with bounded concurrency (default 4)What does NOT ship (deferred per issue body)
Trade-offs (documented in
rag.doc.md)Diffstat
Closes