Skip to content

Commit e2d38b3

Browse files
tae2089claude
andauthored
Trim the ragindex RAG builder and dead retrieval scoring (#7)
* Delete dead tree-retrieval scoring subsystem from ragindex ragindex's Retrieve/RetrieveWithOptions and their ~25-function scoring subsystem (query expansion, whole-word matching, per-bucket scoring, match capping) had zero callers: retrieve_docs went DB-backed and uses only the ragindex result types, not the in-tree Retrieve. Remove the dead functions (~800 lines) and their 12 tests. The kept surface — TreeNode, Search, FindNode, PruneTree, SearchTextForAnnotation, the detail types — is unchanged and still used by the wiki and retrieval. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Remove the community-based RAG index builder and its tools Nothing reads doc-index.json (the RAG builder's only output): retrieve_docs is DB-backed, get_rag_tree built the tree live, and the wiki builds its own folder tree via wikiindex. Remove the ragindex.Builder (community-table tree construction), the build_rag_index and get_rag_tree MCP tools, the ccg rag-index CLI command, and the RAG-index generation in ccg docs. ragindex shrinks from ~1,600 to ~250 lines, keeping only the shared DTOs (TreeNode, SearchResult, RetrieveResult, detail types, Index) and pure helpers (Search, FindNode, PruneTree, SearchTextForAnnotation, LoadIndex) that retrieve_docs, search_docs, and the wiki still use. MCP tools: 33 -> 31. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 6262574 commit e2d38b3

13 files changed

Lines changed: 21 additions & 4195 deletions

internal/cli/docs.go

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import (
99
"github.com/spf13/viper"
1010
"github.com/tae2089/trace"
1111

12-
"github.com/tae2089/code-context-graph/internal/analysis/community"
1312
"github.com/tae2089/code-context-graph/internal/ctxns"
1413
"github.com/tae2089/code-context-graph/internal/docs"
15-
"github.com/tae2089/code-context-graph/internal/ragindex"
1614
"github.com/tae2089/code-context-graph/internal/wikiindex"
1715
)
1816

@@ -26,9 +24,6 @@ func newDocsCmd(deps *Deps) *cobra.Command {
2624
var projectDesc string
2725
var excludePatterns []string
2826
var prune bool
29-
var buildRAG bool
30-
var refreshRAG bool
31-
var communityDepth int
3227

3328
cmd := &cobra.Command{
3429
Use: "docs",
@@ -68,49 +63,18 @@ func newDocsCmd(deps *Deps) *cobra.Command {
6863
return trace.Wrap(err, "build wiki index")
6964
}
7065
fmt.Fprintf(stdout(cmd), "Wiki index written: %d packages, %d files\n", wikiPackages, wikiFiles)
71-
if buildRAG {
72-
communities, files, rebuilt, err := buildDocsRAGIndex(cmd.Context(), deps, docsRAGOptions{
73-
OutDir: absOut,
74-
IndexDir: resolveRagIndexDir(ragIndexDir),
75-
ProjectDesc: resolveRagDescription(projectDesc),
76-
Refresh: refreshRAG,
77-
CommunityDepth: communityDepth,
78-
Namespace: viper.GetString("namespace"),
79-
})
80-
if err != nil {
81-
return trace.Wrap(err, "build rag index")
82-
}
83-
if rebuilt {
84-
fmt.Fprintf(stdout(cmd), "Communities rebuilt for RAG index\n")
85-
}
86-
fmt.Fprintf(stdout(cmd), "RAG index written: %d communities, %d files\n", communities, files)
87-
}
8866
return nil
8967
},
9068
}
9169

9270
cmd.Flags().StringVar(&outDir, "out", "docs", "Output directory for generated documentation")
93-
cmd.Flags().BoolVar(&buildRAG, "rag", true, "Build RAG index from generated docs and community structure")
94-
cmd.Flags().BoolVar(&refreshRAG, "rag-refresh", true, "Refresh community structure before building the RAG index")
95-
cmd.Flags().StringVar(&ragIndexDir, "rag-index-dir", ".ccg", "Directory for doc-index.json output")
96-
cmd.Flags().StringVar(&projectDesc, "rag-desc", "", "Project description for root RAG node summary")
97-
cmd.Flags().IntVar(&communityDepth, "rag-community-depth", 2, "Directory depth for community detection when refreshing RAG communities")
71+
cmd.Flags().StringVar(&ragIndexDir, "rag-index-dir", ".ccg", "Directory for the wiki index output")
72+
cmd.Flags().StringVar(&projectDesc, "rag-desc", "", "Project description for root wiki node summary")
9873
cmd.Flags().StringArrayVar(&excludePatterns, "exclude", nil, "Exclude files/paths matching pattern (repeatable, e.g. --exclude vendor --exclude '*.pb.go')")
9974
cmd.Flags().BoolVar(&prune, "prune", true, "Prune stale generator-managed docs no longer present in the graph")
10075
return cmd
10176
}
10277

103-
// docsRAGOptions carries the RAG build controls derived from docs command flags.
104-
// @intent keep docs generation and RAG indexing options explicit without widening cobra command state.
105-
type docsRAGOptions struct {
106-
OutDir string
107-
IndexDir string
108-
ProjectDesc string
109-
Refresh bool
110-
CommunityDepth int
111-
Namespace string
112-
}
113-
11478
// @intent keep ccg docs Wiki-index settings separate from community-based RAG options.
11579
type docsWikiOptions struct {
11680
OutDir string
@@ -140,37 +104,6 @@ func buildDocsWikiIndex(ctx context.Context, deps *Deps, opts docsWikiOptions) (
140104
return b.Build(ctx)
141105
}
142106

143-
// buildDocsRAGIndex creates the vectorless RAG index after docs generation.
144-
// @intent make ccg docs the default entrypoint for natural-language agent exploration.
145-
// @requires opts.OutDir must point to generated Markdown docs.
146-
// @sideEffect may rebuild community rows and writes doc-index.json.
147-
func buildDocsRAGIndex(ctx context.Context, deps *Deps, opts docsRAGOptions) (int, int, bool, error) {
148-
if opts.CommunityDepth < 1 || opts.CommunityDepth > 8 {
149-
return 0, 0, false, trace.New("rag-community-depth must be between 1 and 8")
150-
}
151-
ns := opts.Namespace
152-
if ns == "" {
153-
ns = ctxns.DefaultNamespace
154-
}
155-
ctx = ctxns.WithNamespace(ctx, ns)
156-
157-
rebuilt := opts.Refresh
158-
if rebuilt {
159-
if _, err := community.New(deps.DB).Rebuild(ctx, community.Config{Depth: opts.CommunityDepth}); err != nil {
160-
return 0, 0, false, err
161-
}
162-
}
163-
164-
b := &ragindex.Builder{
165-
DB: deps.DB,
166-
OutDir: opts.OutDir,
167-
IndexDir: namespaceRagIndexDir(opts.IndexDir, ns),
168-
ProjectDesc: opts.ProjectDesc,
169-
}
170-
communities, files, err := b.Build(ctx)
171-
return communities, files, rebuilt, err
172-
}
173-
174107
// @intent align CLI RAG index output with MCP and Wiki server namespace lookup paths.
175108
func namespaceRagIndexDir(baseDir, namespace string) string {
176109
if ctxns.Normalize(namespace) == ctxns.DefaultNamespace {

internal/cli/docs_test.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -67,95 +67,6 @@ func TestDocsCommand_WritesIndexAndFileDocs(t *testing.T) {
6767
}
6868
}
6969

70-
func TestDocsCommand_BuildsRAGIndexByDefault(t *testing.T) {
71-
deps, stdout, stderr, db := setupDocsTest(t)
72-
73-
db.Create(&model.Node{
74-
Namespace: ctxns.DefaultNamespace,
75-
QualifiedName: "pkg.Main",
76-
Kind: model.NodeKindFunction,
77-
Name: "Main",
78-
FilePath: "pkg/main.go",
79-
StartLine: 1, EndLine: 5,
80-
Hash: "h1", Language: "go",
81-
})
82-
83-
outDir := t.TempDir()
84-
indexDir := t.TempDir()
85-
if err := executeCmd(deps, stdout, stderr, "docs", "--out", outDir, "--rag-index-dir", indexDir); err != nil {
86-
t.Fatalf("docs: %v", err)
87-
}
88-
89-
if _, err := os.Stat(filepath.Join(indexDir, "doc-index.json")); err != nil {
90-
t.Fatalf("expected doc-index.json to be created: %v", err)
91-
}
92-
out := stdout.String()
93-
if !strings.Contains(out, "Communities rebuilt for RAG index") {
94-
t.Fatalf("expected community rebuild output, got:\n%s", out)
95-
}
96-
if !strings.Contains(out, "RAG index written: 1 communities, 1 files") {
97-
t.Fatalf("expected rag index output, got:\n%s", out)
98-
}
99-
}
100-
101-
func TestDocsCommand_BuildsNamespaceIndexes(t *testing.T) {
102-
deps, stdout, stderr, db := setupDocsTest(t)
103-
104-
db.Create(&model.Node{
105-
Namespace: "alpha",
106-
QualifiedName: "pkg.Main",
107-
Kind: model.NodeKindFunction,
108-
Name: "Main",
109-
FilePath: "pkg/main.go",
110-
StartLine: 1, EndLine: 5,
111-
Hash: "h1", Language: "go",
112-
})
113-
114-
outDir := t.TempDir()
115-
indexDir := t.TempDir()
116-
if err := executeCmd(deps, stdout, stderr, "--namespace", "alpha", "docs", "--out", outDir, "--rag-index-dir", indexDir); err != nil {
117-
t.Fatalf("docs: %v", err)
118-
}
119-
120-
if _, err := os.Stat(filepath.Join(indexDir, "alpha", "doc-index.json")); err != nil {
121-
t.Fatalf("expected namespace doc-index.json to be created: %v", err)
122-
}
123-
if _, err := os.Stat(filepath.Join(indexDir, "alpha", "wiki-index.json")); err != nil {
124-
t.Fatalf("expected namespace wiki-index.json to be created: %v", err)
125-
}
126-
if _, err := os.Stat(filepath.Join(indexDir, "doc-index.json")); !os.IsNotExist(err) {
127-
t.Fatalf("default doc-index.json should not be written for named namespace, stat err=%v", err)
128-
}
129-
out := stdout.String()
130-
if !strings.Contains(out, "Wiki index written:") || !strings.Contains(out, "RAG index written:") {
131-
t.Fatalf("expected index output, got:\n%s", out)
132-
}
133-
}
134-
135-
func TestDocsCommand_RAGFlagCanDisableIndexBuild(t *testing.T) {
136-
deps, stdout, stderr, db := setupDocsTest(t)
137-
138-
db.Create(&model.Node{
139-
Namespace: ctxns.DefaultNamespace,
140-
QualifiedName: "pkg.Main",
141-
Kind: model.NodeKindFunction,
142-
Name: "Main",
143-
FilePath: "pkg/main.go",
144-
StartLine: 1, EndLine: 5,
145-
Hash: "h1", Language: "go",
146-
})
147-
148-
outDir := t.TempDir()
149-
indexDir := t.TempDir()
150-
if err := executeCmd(deps, stdout, stderr, "docs", "--out", outDir, "--rag=false", "--rag-index-dir", indexDir); err != nil {
151-
t.Fatalf("docs --rag=false: %v", err)
152-
}
153-
154-
if _, err := os.Stat(filepath.Join(indexDir, "doc-index.json")); !os.IsNotExist(err) {
155-
t.Fatalf("doc-index.json should not be created when --rag=false, stat err=%v", err)
156-
}
157-
}
158-
15970
func TestDocsCommand_NoDB(t *testing.T) {
16071
deps, stdout, stderr := newTestDeps()
16172
// deps.DB == nil

internal/cli/ragindex.go

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)