Documentation
¶
Index ¶
- Constants
- func DetectLanguage(filename string) string
- func DetectProjectLanguage(dir string) string
- func IsIndexableFile(filename string) bool
- func JaccardSimilarity(a, b MinHashSignature) float64
- func ShinglesForSymbol(sym Symbol, source []byte) []string
- func ShouldSkipPath(path string) bool
- type Edge
- type EdgeKind
- type FileRecord
- type GenericParser
- type GoParser
- type Indexer
- func (idx *Indexer) Build() error
- func (idx *Indexer) Close() error
- func (idx *Indexer) KeywordSearch(query string, limit int) ([]Symbol, error)
- func (idx *Indexer) ProjectSummary() string
- func (idx *Indexer) SemanticSearch(query string, topK int) ([]SearchResult, error)
- func (idx *Indexer) Stats() (*StoreStats, error)
- func (idx *Indexer) Store() *Store
- func (idx *Indexer) Update() error
- type MinHashEntry
- type MinHashSignature
- type MinHasher
- type ParseResult
- type RawEdge
- type SearchResult
- type Store
- func (s *Store) AddEdge(sourceID, targetID int64, kind EdgeKind) error
- func (s *Store) Close() error
- func (s *Store) DeleteFile(path string) error
- func (s *Store) DeleteFileSymbols(file string) error
- func (s *Store) GetAllFiles() ([]FileRecord, error)
- func (s *Store) GetAllMinHashes() ([]MinHashEntry, error)
- func (s *Store) GetEdgesFrom(sourceID int64) ([]Edge, error)
- func (s *Store) GetEdgesTo(targetID int64) ([]Edge, error)
- func (s *Store) GetFile(path string) (*FileRecord, error)
- func (s *Store) GetMinHash(symbolID int64) (MinHashSignature, error)
- func (s *Store) GetSymbol(id int64) (*Symbol, error)
- func (s *Store) GetSymbolIDByName(name string) (int64, bool)
- func (s *Store) GetSymbolsByFile(file string) ([]Symbol, error)
- func (s *Store) GetSymbolsByPackage(pkg string) ([]Symbol, error)
- func (s *Store) SearchSymbolsByName(query string) ([]Symbol, error)
- func (s *Store) Stats() (*StoreStats, error)
- func (s *Store) UpdateMinHash(symbolID int64, sig MinHashSignature) error
- func (s *Store) UpsertFile(f FileRecord) error
- func (s *Store) UpsertSymbol(sym Symbol) (int64, error)
- type StoreStats
- type Symbol
- type SymbolKind
Constants ¶
const DefaultNumHashes = 128
DefaultNumHashes is the number of hash functions used for MinHash signatures. 128 provides good accuracy with sub-10ms query time for 50k symbols.
Variables ¶
This section is empty.
Functions ¶
func DetectLanguage ¶
DetectLanguage returns the language for a file based on its extension. Returns empty string if the language is not recognized.
func DetectProjectLanguage ¶
DetectProjectLanguage determines the primary language of a project by checking for manifest files in the given directory.
func IsIndexableFile ¶
IsIndexableFile returns true if the file's language has parser support.
func JaccardSimilarity ¶
func JaccardSimilarity(a, b MinHashSignature) float64
JaccardSimilarity estimates the Jaccard similarity between two MinHash signatures. Returns a value between 0.0 (completely different) and 1.0 (identical sets).
func ShinglesForSymbol ¶
ShinglesForSymbol generates enriched shingles for a symbol, used as input to MinHash for semantic similarity search. Each shingle is a lowercased token derived from the symbol's name, types, body references, package, and comments.
func ShouldSkipPath ¶
ShouldSkipPath returns true if the path should be excluded from indexing.
Types ¶
type FileRecord ¶
type FileRecord struct {
Path string
Language string
Size int64
ContentHash string
IndexedAt int64
}
FileRecord tracks indexed files for incremental updates.
type GenericParser ¶
type GenericParser struct {
// contains filtered or unexported fields
}
GenericParser extracts symbols from non-Go source files using regex patterns. Covers Python, JavaScript, TypeScript, and Rust. No call graph (would need tree-sitter / CGo). Focuses on declarations: functions, classes, imports.
func NewGenericParser ¶
func NewGenericParser(language string) *GenericParser
NewGenericParser creates a parser for the given language.
func (*GenericParser) ParseFile ¶
func (p *GenericParser) ParseFile(path string) (*ParseResult, error)
ParseFile parses a source file and extracts symbols using regex.
type GoParser ¶
type GoParser struct{}
GoParser extracts symbols and edges from Go source files using go/ast.
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
Indexer manages the code graph lifecycle: build, update, and query.
func NewIndexer ¶
NewIndexer creates an indexer for the given workspace, using the specified SQLite database path.
func (*Indexer) Build ¶
Build performs a full index of the workspace. Walks the file tree, parses source files, extracts symbols and edges, computes MinHash signatures, and stores everything in SQLite.
func (*Indexer) KeywordSearch ¶
KeywordSearch finds symbols matching a keyword query using SQL LIKE.
func (*Indexer) ProjectSummary ¶
ProjectSummary returns a brief summary suitable for the system prompt.
func (*Indexer) SemanticSearch ¶
func (idx *Indexer) SemanticSearch(query string, topK int) ([]SearchResult, error)
SemanticSearch finds symbols semantically similar to the query string. The query is split into shingles, MinHashed, then compared against all symbol signatures using brute-force Jaccard similarity.
func (*Indexer) Stats ¶
func (idx *Indexer) Stats() (*StoreStats, error)
Stats returns aggregate stats for the indexed codebase.
type MinHashEntry ¶
type MinHashEntry struct {
SymbolID int64
Signature MinHashSignature
}
MinHashEntry pairs a symbol ID with its MinHash signature for bulk queries.
type MinHashSignature ¶
type MinHashSignature []uint64
MinHashSignature is a fixed-length array of hash values for similarity search.
type MinHasher ¶
type MinHasher struct {
// contains filtered or unexported fields
}
MinHasher computes MinHash signatures for sets of shingles. Uses hash/maphash with different seeds to simulate N independent hash functions.
func NewMinHasher ¶
NewMinHasher creates a MinHasher with the specified number of hash functions.
func (*MinHasher) Signature ¶
func (m *MinHasher) Signature(shingles []string) MinHashSignature
Signature computes the MinHash signature for a set of shingles. Each element of the returned slice is the minimum hash value across all shingles for that hash function.
type ParseResult ¶
type ParseResult struct {
Symbols []Symbol
Edges []RawEdge
Source []byte // raw file content for shingle generation
}
ParseResult holds the symbols and edges extracted from a single file.
type RawEdge ¶
RawEdge is an unresolved edge that uses symbol names instead of IDs. Resolved to Edge (with IDs) when inserted into the store.
type SearchResult ¶
SearchResult pairs a symbol with its similarity score.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages the SQLite database for the code graph.
func NewStore ¶
NewStore opens (or creates) a SQLite database at the given path and initializes the schema.
func (*Store) DeleteFile ¶
DeleteFile removes a file record.
func (*Store) DeleteFileSymbols ¶
DeleteFileSymbols removes all symbols (and their edges) for a file.
func (*Store) GetAllFiles ¶
func (s *Store) GetAllFiles() ([]FileRecord, error)
GetAllFiles returns all indexed file records.
func (*Store) GetAllMinHashes ¶
func (s *Store) GetAllMinHashes() ([]MinHashEntry, error)
GetAllMinHashes retrieves all symbol IDs and their MinHash signatures for similarity search. Symbols without a signature are skipped.
func (*Store) GetEdgesFrom ¶
GetEdgesFrom returns all outgoing edges from the given symbol.
func (*Store) GetEdgesTo ¶
GetEdgesTo returns all incoming edges to the given symbol.
func (*Store) GetFile ¶
func (s *Store) GetFile(path string) (*FileRecord, error)
GetFile retrieves a file record by path.
func (*Store) GetMinHash ¶
func (s *Store) GetMinHash(symbolID int64) (MinHashSignature, error)
GetMinHash retrieves the MinHash signature for a symbol.
func (*Store) GetSymbolIDByName ¶ added in v1.8.2
GetSymbolIDByName returns the ID of a symbol by exact name match. If multiple symbols share the same name, returns the first found.
func (*Store) GetSymbolsByFile ¶
GetSymbolsByFile returns all symbols in the given file.
func (*Store) GetSymbolsByPackage ¶
GetSymbolsByPackage returns all symbols in the given package.
func (*Store) SearchSymbolsByName ¶
SearchSymbolsByName returns symbols whose name contains the query (case-insensitive).
func (*Store) Stats ¶
func (s *Store) Stats() (*StoreStats, error)
Stats returns aggregate counts for the indexed codebase.
func (*Store) UpdateMinHash ¶
func (s *Store) UpdateMinHash(symbolID int64, sig MinHashSignature) error
UpdateMinHash stores the MinHash signature for a symbol.
func (*Store) UpsertFile ¶
func (s *Store) UpsertFile(f FileRecord) error
UpsertFile inserts or updates a file record.
type StoreStats ¶
type StoreStats struct {
TotalSymbols int
TotalEdges int
TotalFiles int
SymbolsByKind map[SymbolKind]int
FilesByLang map[string]int
}
StoreStats holds aggregate counts for the indexed codebase.
type Symbol ¶
type Symbol struct {
ID int64
Name string
Kind SymbolKind
Package string
File string
Line int
Signature string
}
Symbol represents a code entity (function, type, interface, etc.).
type SymbolKind ¶
type SymbolKind string
SymbolKind identifies the kind of code symbol.
const ( SymbolFunction SymbolKind = "function" SymbolMethod SymbolKind = "method" SymbolType SymbolKind = "type" SymbolInterface SymbolKind = "interface" SymbolConst SymbolKind = "const" SymbolVar SymbolKind = "var" SymbolStruct SymbolKind = "struct" SymbolImport SymbolKind = "import" SymbolClass SymbolKind = "class" )