Skip to content

Commit a919aaf

Browse files
tae2089claude
andcommitted
refactor: remove chromem-go — pgvector on PostgreSQL replaces it
Remove standalone vector DB (chromem-go) in favor of PostgreSQL pgvector extension which runs alongside AGE on the same database instance. Removed: - chromem-go dependency - VectorStore type and initialization - --embed flag from ccg build - --semantic flag from ccg search Vector search can be added later via pgvector on the same PostgreSQL that already runs AGE, without any additional infrastructure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1020f4c commit a919aaf

6 files changed

Lines changed: 3 additions & 76 deletions

File tree

cmd/ccg/main.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77

88
"github.com/mark3labs/mcp-go/server"
9-
chromem "github.com/philippgille/chromem-go"
109

1110
"gorm.io/driver/mysql"
1211
"gorm.io/driver/postgres"
@@ -62,26 +61,13 @@ func main() {
6261

6362
syncer := incremental.New(st, walkers[".go"])
6463

65-
// Initialize vector DB for semantic search (persisted to disk)
66-
var vectorStore *cli.VectorStore
67-
if os.Getenv("OPENAI_API_KEY") != "" {
68-
vdb := chromem.NewDB()
69-
collection, err := vdb.GetOrCreateCollection("nodes", nil, nil)
70-
if err != nil {
71-
slog.Warn("vector DB init failed", "error", err)
72-
} else {
73-
vectorStore = &cli.VectorStore{DB: vdb, Collection: collection}
74-
}
75-
}
76-
7764
deps := &cli.Deps{
7865
Logger: logger,
7966
DB: db,
8067
Store: st,
8168
SearchBackend: sb,
8269
Walkers: walkers,
8370
Syncer: syncer,
84-
VectorDB: vectorStore,
8571
ServeFunc: func(cfg cli.ServeConfig) error {
8672
return runServe(cfg.DBDriver, cfg.DSN)
8773
},

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.25.5
55
require (
66
github.com/lib/pq v1.12.3
77
github.com/mark3labs/mcp-go v0.47.1
8-
github.com/philippgille/chromem-go v0.7.0
98
github.com/smacker/go-tree-sitter v0.0.0-20240827094217-dd81d9e9be82
109
github.com/spf13/cobra v1.10.2
1110
gorm.io/driver/mysql v1.6.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ github.com/mark3labs/mcp-go v0.47.1 h1:A9sJJ20mscl/ssLYHjodfaoBmq6uuhMG7pAPNYaQy
3838
github.com/mark3labs/mcp-go v0.47.1/go.mod h1:JKTC7R2LLVagkEWK7Kwu7DbmA6iIvnNAod6yrHiQMag=
3939
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
4040
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
41-
github.com/philippgille/chromem-go v0.7.0 h1:4jfvfyKymjKNfGxBUhHUcj1kp7B17NL/I1P+vGh1RvY=
42-
github.com/philippgille/chromem-go v0.7.0/go.mod h1:hTd+wGEm/fFPQl7ilfCwQXkgEUxceYh86iIdoKMolPo=
4341
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4442
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4543
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=

internal/cli/build.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"path/filepath"
88
"strings"
99

10-
chromem "github.com/philippgille/chromem-go"
1110
"github.com/spf13/cobra"
1211

1312
"github.com/imtaebin/code-context-graph/internal/model"
@@ -21,7 +20,6 @@ var skipDirs = map[string]bool{
2120
}
2221

2322
func newBuildCmd(deps *Deps) *cobra.Command {
24-
var embed bool
2523
var syncGraph bool
2624

2725
cmd := &cobra.Command{
@@ -175,27 +173,6 @@ func newBuildCmd(deps *Deps) *cobra.Command {
175173
}
176174
}
177175

178-
// Build vector embeddings if --embed flag is set
179-
if embed && deps.VectorDB != nil {
180-
deps.Logger.Info("building vector embeddings")
181-
for _, n := range indexNodes {
182-
err := deps.VectorDB.Collection.AddDocument(ctx, chromem.Document{
183-
ID: fmt.Sprintf("%d", n.ID),
184-
Content: buildContent(n),
185-
Metadata: map[string]string{
186-
"qualified_name": n.QualifiedName,
187-
"kind": string(n.Kind),
188-
"file_path": n.FilePath,
189-
"language": n.Language,
190-
},
191-
})
192-
if err != nil {
193-
deps.Logger.Warn("embed failed", "node", n.QualifiedName, "error", err)
194-
}
195-
}
196-
deps.Logger.Info("vector embeddings built", "documents", len(indexNodes))
197-
}
198-
199176
// Sync to Apache AGE graph if --graph flag is set
200177
if syncGraph && deps.AgeStore != nil {
201178
deps.Logger.Info("syncing to AGE graph")
@@ -222,7 +199,6 @@ func newBuildCmd(deps *Deps) *cobra.Command {
222199
},
223200
}
224201

225-
cmd.Flags().BoolVar(&embed, "embed", false, "Build vector embeddings for semantic search (requires OPENAI_API_KEY)")
226202
cmd.Flags().BoolVar(&syncGraph, "graph", false, "Sync graph to Apache AGE (requires AGE_DSN)")
227203

228204
return cmd

internal/cli/root.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"log/slog"
66
"os"
77

8-
chromem "github.com/philippgille/chromem-go"
98
"github.com/spf13/cobra"
109
"gorm.io/gorm"
1110

@@ -25,16 +24,9 @@ type Deps struct {
2524
Walkers map[string]*treesitter.Walker
2625
Syncer *incremental.Syncer
2726
ServeFunc func(cfg ServeConfig) error
28-
VectorDB *VectorStore
2927
AgeStore *agestore.Store
3028
}
3129

32-
// VectorStore wraps chromem-go for semantic search.
33-
type VectorStore struct {
34-
DB *chromem.DB
35-
Collection *chromem.Collection
36-
}
37-
3830
// NewRootCmd creates the root cobra command with all subcommands attached.
3931
// If deps is nil, a minimal Deps with a default logger is created.
4032
func NewRootCmd(deps *Deps) *cobra.Command {

internal/cli/search.go

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,45 +9,22 @@ import (
99

1010
func newSearchCmd(deps *Deps) *cobra.Command {
1111
var limit int
12-
var semantic bool
1312

1413
cmd := &cobra.Command{
1514
Use: "search <query>",
16-
Short: "Full-text or semantic search for code nodes",
15+
Short: "Full-text search for code nodes",
1716
Args: cobra.ExactArgs(1),
1817
RunE: func(cmd *cobra.Command, args []string) error {
1918
query := args[0]
2019
ctx := context.Background()
21-
out := stdout(cmd)
22-
23-
// Semantic search via vector embeddings
24-
if semantic {
25-
if deps.VectorDB == nil || deps.VectorDB.Collection == nil {
26-
return fmt.Errorf("vector embeddings not available — run 'ccg build --embed' first")
27-
}
28-
results, err := deps.VectorDB.Collection.Query(ctx, query, limit, nil, nil)
29-
if err != nil {
30-
return fmt.Errorf("semantic search: %w", err)
31-
}
32-
if len(results) == 0 {
33-
fmt.Fprintln(out, "No results")
34-
return nil
35-
}
36-
for _, r := range results {
37-
qn := r.Metadata["qualified_name"]
38-
kind := r.Metadata["kind"]
39-
fp := r.Metadata["file_path"]
40-
fmt.Fprintf(out, "%s\t%s\t%s\t(score: %.3f)\n", qn, kind, fp, r.Similarity)
41-
}
42-
return nil
43-
}
4420

45-
// FTS keyword search
4621
nodes, err := deps.SearchBackend.Query(ctx, deps.DB, query, limit)
4722
if err != nil {
4823
return fmt.Errorf("search: %w", err)
4924
}
5025

26+
out := stdout(cmd)
27+
5128
if len(nodes) == 0 {
5229
fmt.Fprintln(out, "No results")
5330
return nil
@@ -62,7 +39,6 @@ func newSearchCmd(deps *Deps) *cobra.Command {
6239
}
6340

6441
cmd.Flags().IntVar(&limit, "limit", 10, "Maximum number of results")
65-
cmd.Flags().BoolVar(&semantic, "semantic", false, "Use semantic search via vector embeddings")
6642

6743
return cmd
6844
}

0 commit comments

Comments
 (0)