Skip to content

Commit 7644a68

Browse files
committed
feat: add RAG document retrieval
1 parent 6a046ca commit 7644a68

20 files changed

Lines changed: 849 additions & 77 deletions

AGENTS.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## MCP 서버
66

7-
`.mcp.json`에 등록된 ccg MCP 서버가 33개 도구를 제공합니다:
7+
`.mcp.json`에 등록된 ccg MCP 서버가 35개 도구를 제공합니다:
88

99
- `parse_project`, `build_or_update_graph`, `run_postprocess`
1010
- `get_postprocess_policy`, `reset_postprocess_policy`
@@ -14,7 +14,7 @@
1414
- `detect_changes`, `get_affected_flows`, `list_flows`
1515
- `list_communities`, `get_community`, `get_architecture_overview`
1616
- `get_annotation`
17-
- `build_rag_index`, `get_rag_tree`, `get_doc_content`, `search_docs`
17+
- `build_rag_index`, `get_rag_tree`, `get_doc_content`, `search_docs`, `retrieve_docs`
1818
- `upload_file`, `upload_files`, `list_namespaces`, `list_files`, `delete_file`, `delete_namespace`
1919
- `list_workspaces`, `delete_workspace` (deprecated aliases)
2020

@@ -38,8 +38,9 @@ Graceful shutdown: SIGINT/SIGTERM 시 진행 중인 clone/build에 context cance
3838
주요 커맨드:
3939

4040
- `ccg build [dir]` — 코드 그래프 빌드 (`--exclude`, `--no-recursive` 지원)
41+
- `ccg docs [--out dir]` — 마크다운 문서 및 기본 RAG 인덱스 생성
42+
- `ccg rag-index [--out dir]` — 이미 계산된 커뮤니티와 생성 문서 기반 RAG 인덱스 생성
4143
- `ccg search <query>` — 전문 검색 (어노테이션 포함)
42-
- `ccg docs [--out dir]` — 마크다운 문서 생성
4344
- `ccg lint [--strict]` — 문서 품질 체크
4445
- `ccg annotate [file|dir]` — AI 어노테이션 생성
4546

@@ -49,17 +50,18 @@ Graceful shutdown: SIGINT/SIGTERM 시 진행 중인 clone/build에 context cance
4950

5051
코드 위치, 관련 구현, 호출 관계, 영향 범위, 아키텍처 맥락을 찾을 때는 먼저 ccg MCP 도구와 CLI Skills를 활용합니다.
5152

52-
- 의미 기반 검색과 관련 코드 탐색은 ccg MCP `search`, `query_graph`, `get_node`, `get_minimal_context` 또는 `/ccg` skill을 우선 사용합니다.
53+
- 자연어 기반 코드 이해, 모듈 탐색, 아키텍처 맥락 수집은 `/ccg-docs` skill과 `retrieve_docs`, `get_rag_tree`, `get_doc_content`를 우선 사용합니다.
54+
- 정확한 심볼 위치, 호출 관계, 그래프 메타데이터 확인은 ccg MCP `query_graph`, `get_node`, `get_minimal_context` 또는 `/ccg` skill을 사용합니다.
55+
- 어노테이션/키워드 기반 후보 검색은 ccg MCP `search` 또는 `ccg search`를 보조로 사용합니다.
5356
- 영향 범위, 플로우, 데드코드, 구조 분석은 `/ccg-analyze` skill과 관련 MCP 도구(`get_impact_radius`, `trace_flow`, `find_dead_code`, `get_architecture_overview`)를 우선 사용합니다.
54-
- 문서/RAG 기반 맥락 검색은 `/ccg-docs` skill과 `search_docs`, `get_rag_tree`, `get_doc_content`를 우선 사용합니다.
5557
- 단순 문자열 확인, 파일 존재 확인, ccg 인덱스가 없거나 오래된 경우에는 `rg`를 보조로 사용하고, 필요한 경우 `ccg build .` 또는 `ccg update .`로 그래프를 갱신합니다.
5658

5759
## 문서
5860

5961
상세 문서는 `guide/` 디렉토리를 참조하세요:
6062

6163
- [CLI Reference](guide/cli-reference.md) — 전체 명령어, 플래그, 설정 파일
62-
- [MCP Tools](guide/mcp-tools.md)33개 MCP 도구, Skills, AI-Driven Annotation
64+
- [MCP Tools](guide/mcp-tools.md)35개 MCP 도구, Skills, AI-Driven Annotation
6365
- [Annotations](guide/annotations.md) — 어노테이션 태그, 예시, 검색
6466
- [Webhook](guide/webhook.md) — Webhook sync, 브랜치 필터링, HMAC, graceful shutdown
6567
- [Docker](guide/docker.md) — Docker 빌드, MCP 서버, PostgreSQL 배포

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# code-context-graph
22

3-
Local code analysis tool that parses codebases via Tree-sitter into a knowledge graph. Supports 12 languages, 33 MCP tools, and custom annotation search.
3+
Local code analysis tool that parses codebases via Tree-sitter into a knowledge graph. Supports 12 languages, 35 MCP tools, and custom annotation search.
44

55
CCG is built primarily for GPT, Claude, Codex, and other LLM-based coding agents. It acts as local or self-hosted context infrastructure: agents can search code by intent, inspect call graphs, trace impact, retrieve docs, and keep responses bounded instead of reading entire repositories into context.
66

@@ -11,7 +11,8 @@ Inspired by [code-review-graph](https://github.com/tirth8205/code-review-graph)
1111
## Features
1212

1313
- **12 languages**: Go, Python, TypeScript, Java, Ruby, JavaScript, C, C++, Rust, Kotlin, PHP, Lua/Luau
14-
- **33 MCP tools**: parse, search, impact analysis, flow tracing, dead code detection, postprocess operations, namespace file management, and more
14+
- **35 MCP tools**: parse, search, impact analysis, flow tracing, dead code detection, postprocess operations, namespace file management, and more
15+
- **RAG-first code exploration**: generated docs + community structure let LLM agents answer natural-language questions before drilling into exact graph nodes
1516
- **Custom annotations**: `@intent`, `@domainRule`, `@sideEffect`, `@mutates`, `@index` — search code by business context ([details](guide/annotations.md))
1617
- **Webhook sync**: GitHub / Gitea push events → auto clone + build with per-repo branch filtering and `.ccg.yaml` `include_paths` auto-loading ([details](guide/webhook.md))
1718
- **Eval**: Golden corpus-based parser accuracy (P/R/F1) and search quality (P@K, MRR, nDCG) evaluation ([details](guide/eval.md))
@@ -60,6 +61,9 @@ ccg search "authentication"
6061
# Search by business context
6162
ccg search "payment" # finds functions with @intent/@domainRule about payments
6263

64+
# Build docs and the default vectorless RAG index for agent-oriented exploration
65+
ccg docs --out docs
66+
6367
# Graph statistics
6468
ccg status
6569

@@ -77,6 +81,18 @@ ccg eval --suite parser
7781
ccg eval --suite parser --update
7882
```
7983

84+
`ccg docs` refreshes community structure and writes `.ccg/doc-index.json` by
85+
default. Use `--rag=false` when you only want Markdown, or
86+
`--rag-refresh=false` when you want to rebuild the index from existing community
87+
rows without recalculating communities.
88+
89+
For LLM agents, treat generated docs and the RAG index as the primary entrypoint
90+
for natural-language questions such as "how does webhook sync work?" or "where
91+
are the operational risks?". Use graph tools for exact symbols, call relations,
92+
impact radius, and pagination-safe result sets. Use `ccg search` as a focused
93+
annotation/keyword candidate search rather than the first tool for broad code
94+
understanding.
95+
8096
If you use PostgreSQL, a custom SQLite DSN, an existing schema, or a controlled
8197
upgrade workflow, run `ccg migrate` explicitly before runtime commands. This
8298
also applies when upgrading CCG against an existing default `ccg.db` created by
@@ -192,7 +208,7 @@ For remote HTTP mode:
192208
}
193209
```
194210

195-
Claude Code automatically connects and gets access to 33 MCP tools. See [MCP Tools Reference](guide/mcp-tools.md) for the full list.
211+
Claude Code automatically connects and gets access to 35 MCP tools. See [MCP Tools Reference](guide/mcp-tools.md) for the full list.
196212

197213
## Architecture
198214

@@ -223,7 +239,7 @@ See [Architecture Details](guide/architecture.md) for component breakdown and DB
223239
| [CLI Reference](guide/cli-reference.md) | All commands, flags, and config file (`.ccg.yaml`) |
224240
| [Eval](guide/eval.md) | Parser/search quality evaluation, golden corpus, and metrics |
225241
| [Lint](guide/lint.md) | Detailed `ccg lint` category reference, interpretation guide, and CI usage |
226-
| [MCP Tools](guide/mcp-tools.md) | 33 MCP tools, Skills, AI-Driven Annotation |
242+
| [MCP Tools](guide/mcp-tools.md) | 35 MCP tools, Skills, AI-Driven Annotation |
227243
| [Annotations](guide/annotations.md) | Annotation system — tags, examples, search |
228244
| [Webhook](guide/webhook.md) | Webhook sync, branch filtering, HMAC, graceful shutdown |
229245
| [Docker](guide/docker.md) | Docker build, MCP server, PostgreSQL deployment |

guide/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
Documentation index for code-context-graph.
44

5+
For LLM-agent workflows, start natural-language code exploration from generated
6+
docs and the RAG index. Use graph/search tools after the relevant module,
7+
document, or symbol candidate is identified.
8+
59
| Document | Description |
610
|----------|-------------|
711
| [CLI Reference](cli-reference.md) | Full CLI commands, options, and configuration file (`.ccg.yaml`) |
812
| [Eval](eval.md) | Parser/search quality evaluation, golden corpus, and metrics |
913
| [Lint](lint.md) | Detailed `ccg lint` category reference, interpretation guide, and CI usage |
10-
| [MCP Tools](mcp-tools.md) | 33 MCP tools, Claude Code Skills, AI-driven annotation |
11-
| [Annotations](annotations.md) | Custom annotation system — tags, examples, search |
14+
| [MCP Tools](mcp-tools.md) | 35 MCP tools, Claude Code Skills, RAG-first routing, AI-driven annotation |
15+
| [Annotations](annotations.md) | Custom annotation system — tags, examples, search/RAG quality |
1216
| [Webhook](webhook.md) | GitHub / Gitea webhook sync, branch filtering, graceful shutdown |
1317
| [Docker](docker.md) | Docker image build, MCP server setup, PostgreSQL integration |
1418
| [Operations](operations.md) | Deployment profiles, database choice, readiness, webhook operations, troubleshooting |

guide/annotations.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Custom Annotations
22

3-
Add structured metadata to your code so that AI and search can leverage business context. Annotations are indexed and searchable via `ccg search`.
3+
Add structured metadata to your code so that AI, generated docs, RAG, and
4+
focused search can leverage business context. Annotations are indexed for
5+
`ccg search` and are also rendered into generated Markdown that feeds the RAG
6+
index.
7+
8+
For LLM-agent natural-language exploration, prefer the docs/RAG path first:
9+
`ccg docs`, then MCP `retrieve_docs`, `get_rag_tree`, and `get_doc_content`.
10+
Use `ccg search` when you need a focused list of
11+
annotation/keyword-matched symbol candidates.
412

513
Annotation quality is validated by `ccg lint`. For category meanings such as `unannotated`, `incomplete`, `dead-ref`, `contradiction`, and `drifted`, see [Lint Guide](lint.md).
614

guide/cli-reference.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ ccg update ./backend --namespace backend
4646
| `ccg status --recent <n>` | Number of recent postprocess failures to inspect (default `5`) |
4747
| `ccg search <query>` | Full-text search |
4848
| `ccg search --path <prefix> <query>` | Scoped search by path prefix |
49-
| `ccg docs [--out dir]` | Generate Markdown documentation (prunes stale generator-managed docs by default) |
49+
| `ccg docs [--out dir]` | Generate Markdown documentation and the default RAG index (prunes stale generator-managed docs by default) |
50+
| `ccg docs --rag=false` | Generate Markdown only, without rebuilding communities or the RAG index |
51+
| `ccg docs --rag-refresh=false` | Rebuild the RAG index from existing community rows instead of refreshing communities |
52+
| `ccg docs --rag-index-dir <dir>` | Override the doc-index.json output directory (default `.ccg` or `rag.index_dir`) |
5053
| `ccg docs --prune=false` | Regenerate docs without deleting older generator-managed files |
5154
| `ccg docs --exclude <pat>` | Exclude files/paths from generated docs (repeatable) |
5255
| `ccg index [--out dir]` | Regenerate `index.md` only |
53-
| `ccg rag-index [--out dir]` | Build RAG index from generated docs and community structure |
56+
| `ccg rag-index [--out dir]` | Rebuild RAG index from generated docs and already-computed community structure |
5457
| `ccg languages` | List supported languages and extensions |
5558
| `ccg example [language]` | Show annotation writing example |
5659
| `ccg tags` | Show all annotation tag reference |
@@ -63,6 +66,37 @@ ccg update ./backend --namespace backend
6366

6467
For the default local SQLite database (`ccg.db`, including `./ccg.db`, absolute paths ending in `ccg.db`, and `file:` DSNs for that file), runtime commands auto-run migrations only when the schema is missing. Existing SQLite schemas, PostgreSQL, custom SQLite DSNs, and controlled upgrades require an explicit `ccg migrate`. If you already have a default `ccg.db` from an older CCG version, treat it as an existing schema and run `ccg migrate` after upgrading.
6568

69+
### Search and RAG Routing
70+
71+
CCG has two search surfaces with different jobs:
72+
73+
| Use case | Preferred entrypoint |
74+
|----------|----------------------|
75+
| Natural-language code understanding, module exploration, architecture questions | `ccg docs`, then MCP `retrieve_docs`, `get_rag_tree`, `get_doc_content` |
76+
| Exact symbol lookup, callers/callees, imports, bounded graph traversal | MCP `get_node`, `query_graph`, `get_minimal_context` |
77+
| Impact analysis, flow tracing, dead code, large functions | MCP analysis tools such as `get_impact_radius`, `trace_flow`, `find_dead_code`, `find_large_functions` |
78+
| Focused annotation/keyword candidate search | `ccg search` or MCP `search` |
79+
80+
For coding agents, the recommended natural-language path is:
81+
82+
```bash
83+
ccg build .
84+
ccg docs --out docs
85+
```
86+
87+
`ccg docs` refreshes community structure and writes the default
88+
`.ccg/doc-index.json` RAG index unless `--rag=false` is set. Use
89+
`--rag-refresh=false` only when you intentionally want to reuse existing
90+
community rows. The standalone `ccg rag-index` command remains available for
91+
manual rebuilds from generated docs and already-computed communities.
92+
93+
Then use MCP `retrieve_docs` to retrieve document candidates and bounded
94+
Markdown content with tree evidence. Use `get_rag_tree` to expand the
95+
module/community context and `get_doc_content` to read a specific generated doc
96+
directly. `search_docs` and `ccg search` remain useful for quick keyword or
97+
annotation matches, but they should not be treated as the primary answering
98+
surface for broad natural-language questions.
99+
66100
### Database Choice
67101

68102
Use SQLite for local, single-user workflows where the database is a disposable

guide/ko/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ code-context-graph의 문서 인덱스입니다. 한국어 문서는 영어 가
66

77
CCG는 GPT, Claude, Codex 같은 LLM 기반 코딩 에이전트가 개발 중 코드베이스 맥락을 정확하고 작게 가져오도록 만든 로컬/셀프호스트 context infrastructure입니다. 일반 SaaS 관리자용 제품이 아니라, CLI, MCP, 로그, 문서를 이해하는 개발자와 코딩 에이전트가 코드 검색, 영향 분석, 호출 그래프, 문서/RAG, bounded response를 활용하도록 설계되었습니다.
88

9+
LLM 에이전트 워크플로우에서는 자연어 기반 코드 탐색을 생성 문서와 RAG 인덱스에서 시작하십시오. 관련 모듈, 문서 또는 심볼 후보를 찾은 뒤 graph/search 도구로 정확한 위치와 관계를 확인하는 흐름을 권장합니다.
10+
911
| 문서 | 설명 |
1012
|------|------|
1113
| [CLI 레퍼런스](cli-reference.md) | 모든 CLI 명령어, 옵션 및 설정 파일(`.ccg.yaml`) 안내 |
1214
| [Eval](eval.md) | 파서/검색 품질 평가, golden corpus, 지표 설명 |
1315
| [Lint](lint.md) | `ccg lint` 카테고리 상세 레퍼런스, 결과 해석 및 CI 활용법 |
14-
| [MCP 도구](mcp-tools.md) | 33개의 MCP 도구, Claude Code Skill, AI 기반 어노테이션 |
15-
| [어노테이션](annotations.md) | 커스텀 어노테이션 시스템 — 태그, 예시, 검색 방법 |
16+
| [MCP 도구](mcp-tools.md) | 35개의 MCP 도구, Claude Code Skill, RAG 우선 라우팅, AI 기반 어노테이션 |
17+
| [어노테이션](annotations.md) | 커스텀 어노테이션 시스템 — 태그, 예시, 검색/RAG 품질 |
1618
| [웹훅(Webhook)](webhook.md) | GitHub / Gitea 웹훅 동기화, 브랜치 필터링, Graceful Shutdown |
1719
| [Docker](docker.md) | Docker 이미지 빌드, MCP 서버 설정, PostgreSQL 연동 |
1820
| [운영(Operations)](operations.md) | 배포 프로필, 데이터베이스 선택, 준비성 체크, 웹훅 운영 및 문제 해결 |

guide/ko/annotations.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
[English](../annotations.md)
44

5-
코드에 구조화된 메타데이터를 추가하여 AI와 검색 엔진이 비즈니스 컨텍스트를 활용할 수 있도록 합니다. 어노테이션은 인덱싱되어 `ccg search`를 통해 검색할 수 있습니다.
5+
코드에 구조화된 메타데이터를 추가하여 AI, 생성 문서, RAG, 집중 검색이 비즈니스 컨텍스트를 활용할 수 있도록 합니다. 어노테이션은 `ccg search`를 위해 인덱싱되며, RAG 인덱스의 입력이 되는 생성 Markdown에도 반영됩니다.
6+
7+
LLM 에이전트의 자연어 기반 코드 탐색에는 docs/RAG 경로를 먼저 사용하십시오. `ccg docs`를 실행한 뒤 MCP `retrieve_docs`, `get_rag_tree`, `get_doc_content`를 사용합니다. `ccg search`는 어노테이션/키워드에 매칭되는 심볼 후보 목록이 필요할 때 사용하십시오.
68

79
어노테이션 품질은 `ccg lint`에 의해 검증됩니다. `unannotated`, `incomplete`, `dead-ref`, `contradiction`, `drifted`와 같은 카테고리의 의미는 [Lint 가이드](lint.md)를 참조하십시오.
810

guide/ko/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
1212
FTS 검색
1313
14-
MCP 서버 (33개 도구)
14+
MCP 서버 (35개 도구)
1515
↓ ↓
1616
stdio Streamable HTTP
1717
↓ ↓
@@ -74,7 +74,7 @@ GORM ORM 기반 저장소입니다. SQLite 및 PostgreSQL과 호환됩니다.
7474

7575
### MCP 서버 (MCP Server) (`internal/mcp/`)
7676

77-
MCP 프로토콜을 통해 33개의 도구를 노출합니다. stdio 및 Streamable HTTP 두 가지 전송 모드를 지원합니다.
77+
MCP 프로토콜을 통해 35개의 도구를 노출합니다. stdio 및 Streamable HTTP 두 가지 전송 모드를 지원합니다.
7878

7979
### 안정성 (Reliability)
8080

0 commit comments

Comments
 (0)