feat(brainstore): shared BrainStore impl; re-point MCP handlers (#51)
Extracts the #45 write/update/get logic + the wiki upkeep that must accompany a write (wing _index rebuild, cross-wing auto-tunnel, graph re-index) into a single concrete brainstore.Store implementing capture.BrainStore. The MCP brain_write/brain_update/brain_get handlers are re-pointed at it, so there is one implementation, not two — the DRY payoff #51 is named for. capture and MCP now share the exact same brain write path and read-after-write contract. The Server gains a *brainstore.Store, constructed in NewServer and given the graph store in WithGraph. Embedding refresh stays out-of-band (mtime-driven vectorstore.Sync), unchanged. Existing MCP brain_update/ brain_get/brain_write tests pass unmodified — behaviour and the {id, path, content_hash} response contract are preserved. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/brainstore"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/graphstore"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/graphsync"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/pipeline"
|
||||
@@ -46,6 +47,7 @@ type Server struct {
|
||||
vector search.VectorSearcher // nil = BM25-only retrieval
|
||||
embedder search.Embedder // nil = BM25-only retrieval
|
||||
graph graphsync.Store // nil = brain_graph and GraphRAG augmentation disabled
|
||||
store *brainstore.Store // shared brain write/update/get impl (also used by capture)
|
||||
}
|
||||
|
||||
// NewServer constructs a Server bound to brainDir. pipelineCfg supplies the
|
||||
@@ -56,7 +58,13 @@ func NewServer(brainDir string, pipelineCfg *pipeline.Config, llm pipeline.Compl
|
||||
if pipelineCfg != nil {
|
||||
cfg = *pipelineCfg
|
||||
}
|
||||
return &Server{brainDir: brainDir, pipeline: cfg, llm: llm, answerLLM: answerLLM}
|
||||
return &Server{
|
||||
brainDir: brainDir,
|
||||
pipeline: cfg,
|
||||
llm: llm,
|
||||
answerLLM: answerLLM,
|
||||
store: brainstore.New(brainDir),
|
||||
}
|
||||
}
|
||||
|
||||
// WithReranker installs an opt-in cross-encoder reranker. When set,
|
||||
@@ -84,9 +92,11 @@ func (s *Server) WithHybridRetrieval(v search.VectorSearcher, e search.Embedder)
|
||||
func (s *Server) WithGraph(g *graphstore.PGStore) *Server {
|
||||
if g == nil {
|
||||
s.graph = nil
|
||||
s.store.WithGraph(nil)
|
||||
return s
|
||||
}
|
||||
s.graph = g
|
||||
s.store.WithGraph(g)
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user