ragindex

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

@index ragindex 패키지는 DB의 커뮤니티/어노테이션 데이터를 읽어 doc-index.json을 빌드한다.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	DB          *gorm.DB
	OutDir      string // docs 디렉토리 (기본: "docs")
	IndexDir    string // .ccg 디렉토리 (기본: ".ccg")
	ProjectDesc string // root 노드 summary (기본: "")
}

Builder는 DB에서 인덱스를 빌드하는 구조체이다. @intent 그래프 DB와 문서 출력 경로를 연결해 doc-index.json 생성을 조율한다.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context) (int, int, error)

Build는 DB에서 커뮤니티와 멤버 노드를 읽어 doc-index.json을 생성한다. 반환값: (커뮤니티 수, 파일 수, 에러) @intent 커뮤니티 구조와 문서 요약을 트리 형태 인덱스로 합성한다. @sideEffect 데이터베이스를 읽고 doc-index.json 파일을 기록한다. @ensures 성공 시 반환된 파일 수는 인덱스에 포함된 고유 파일 수와 같다.

type Index

type Index struct {
	Version int       `json:"version"`
	BuiltAt time.Time `json:"built_at"`
	Root    *TreeNode `json:"root"`
}

Index는 .ccg/doc-index.json 전체 포맷이다. @intent 디스크에 저장되는 문서 인덱스 루트 페이로드를 정의한다.

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex는 주어진 경로에서 doc-index.json을 읽어 Index를 반환한다. @intent 저장된 RAG 인덱스를 도구나 서버가 다시 로드할 수 있게 한다. @sideEffect 대상 JSON 파일을 읽는다.

type RetrieveResult

type RetrieveResult struct {
	ID           string         `json:"id"`
	Label        string         `json:"label"`
	Summary      string         `json:"summary"`
	DocPath      string         `json:"doc_path"`
	Path         []string       `json:"path"`
	Score        int            `json:"score"`
	MatchedTerms []string       `json:"matched_terms"`
	Matches      []SearchResult `json:"matches,omitempty"`
}

RetrieveResult represents one document candidate selected from tree-aware query matching. @intent return file-level RAG retrieval candidates with the matched tree evidence that caused the hit.

func Retrieve

func Retrieve(root *TreeNode, query string, maxResults int) []RetrieveResult

Retrieve scores file nodes by matching query terms against the file node and its symbol descendants. @intent support PageIndex-style document retrieval where multiple query terms can be satisfied across one subtree. @requires query must contain at least one searchable term.

type SearchResult

type SearchResult struct {
	ID      string   `json:"id"`
	Label   string   `json:"label"`
	Summary string   `json:"summary"`
	DocPath string   `json:"doc_path,omitempty"`
	Path    []string `json:"path"` // root부터 해당 노드까지의 Label 경로
}

SearchResult는 Search 함수가 반환하는 단일 매칭 결과이다. @intent 검색 UI나 MCP 응답에서 표시할 최소 결과 정보를 담는다.

func Search(root *TreeNode, query string, maxResults int) []SearchResult

Search는 root 트리를 DFS로 순회하며 query를 Label과 Summary에서 case-insensitive 검색하여 최대 maxResults개의 결과를 반환한다. root 노드 자체는 결과에 포함하지 않는다. @intent 문서 인덱스 트리에서 제목과 요약 기반 키워드 탐색을 제공한다. @requires query가 비어 있지 않아야 의미 있는 결과가 나온다.

type TreeNode

type TreeNode struct {
	ID       string      `json:"id"`
	Label    string      `json:"label"`
	Summary  string      `json:"summary"`
	DocPath  string      `json:"doc_path,omitempty"` // file 노드만 설정
	Children []*TreeNode `json:"children"`
}

TreeNode는 doc-index.json의 단일 노드이다. @intent RAG 탐색 트리에서 커뮤니티, 파일, 심볼 노드를 동일 구조로 표현한다.

func FindNode

func FindNode(root *TreeNode, id string) *TreeNode

FindNode는 root 트리에서 id와 일치하는 TreeNode를 재귀적으로 찾아 반환한다. 없으면 nil을 반환한다. @intent 인덱스 트리에서 특정 노드를 ID로 직접 찾을 수 있게 한다.

func PruneTree

func PruneTree(root *TreeNode, maxDepth int) *TreeNode

PruneTree는 root 트리를 maxDepth 깊이까지만 포함한 새 트리를 반환한다. maxDepth <= 0이면 전체 트리를 반환한다. 원본 트리는 변경하지 않는다. depth 계산: root는 depth 0, root의 직계 자식은 depth 1. @intent 대형 인덱스를 요약 응답에 맞게 깊이 제한된 복사본으로 축약한다. @ensures 원본 트리는 수정되지 않는다.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL