storage

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEmbeddingDim = 384

DefaultEmbeddingDim is the default embedding dimension (TFIDF fallback).

Variables

This section is empty.

Functions

func BuildSearchTerms

func BuildSearchTerms(symbolName, filePath string) string

BuildSearchTerms produces a space-separated string of tokens derived from the symbol name (CamelCase-split) and the file basename (split on . _ -). This string is stored in the FTS index so that inner tokens of compound identifiers like "PaymentMappingService" become individually searchable. The original unsplit symbol name and file basename are prepended (preserving case) to enable compound prefix matching, matching the C reference codebase's behavior.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages all SQLite database operations

func NewStore

func NewStore(dbPath string, embeddingDim ...int) (*Store, error)

NewStore opens (or creates) a SQLite database at the given path and runs migrations. embeddingDim sets the expected embedding vector dimension (0 uses DefaultEmbeddingDim).

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying sql.DB for raw queries. WARNING: Bypasses all safety checks (read-only enforcement, blocklist). Use RawQuery for safe user-facing queries. Only use DB() for internal operations.

func (*Store) DeleteByFile

func (s *Store) DeleteByFile(filePath string) error

DeleteByFile removes all nodes and their edges for a given file path

func (*Store) DeleteFTSByFile

func (s *Store) DeleteFTSByFile(filePath string) error

DeleteFTSByFile removes FTS entries for all nodes in a file

func (*Store) FindRouteNodesByKeywords

func (s *Store) FindRouteNodesByKeywords(keywords []string, limit int) ([]types.SearchResult, error)

FindRouteNodesByKeywords searches for route-type nodes whose search_terms contain any of the given keywords. Returns matching route nodes with relevance scoring.

func (*Store) GetAllBetweenness

func (s *Store) GetAllBetweenness() (map[string]float64, error)

GetAllBetweenness retrieves all betweenness centrality scores as a map

func (*Store) GetAllEdges

func (s *Store) GetAllEdges() ([]types.ASTEdge, error)

GetAllEdges retrieves all edges from the database

func (*Store) GetAllFilePaths

func (s *Store) GetAllFilePaths() ([]string, error)

GetAllFilePaths returns all unique file paths from the nodes table

func (*Store) GetAllNodeIDs

func (s *Store) GetAllNodeIDs() ([]string, error)

GetAllNodeIDs retrieves all node IDs from the database

func (*Store) GetAllNodeScores

func (s *Store) GetAllNodeScores() ([]types.NodeScore, error)

GetAllNodeScores returns all node scores as a slice

func (*Store) GetAllProjectSummaries

func (s *Store) GetAllProjectSummaries() ([]types.ProjectSummary, error)

GetAllProjectSummaries retrieves all project summaries

func (*Store) GetEdgesFrom

func (s *Store) GetEdgesFrom(nodeID string) ([]types.ASTEdge, error)

GetEdgesFrom retrieves all outgoing edges from a node

func (*Store) GetEdgesTo

func (s *Store) GetEdgesTo(nodeID string) ([]types.ASTEdge, error)

GetEdgesTo retrieves all incoming edges to a node

func (*Store) GetFileIntent

func (s *Store) GetFileIntent(filePath string) (*gitmeta.FileIntent, error)

GetFileIntent returns the stored intent summary for a file.

func (*Store) GetFileIntentsByPaths

func (s *Store) GetFileIntentsByPaths(paths []string) (map[string]*gitmeta.FileIntent, error)

GetFileIntentsByPaths returns intent summaries for multiple files.

func (*Store) GetIncomingCrossFileEdges

func (s *Store) GetIncomingCrossFileEdges(filePath string) ([]types.ASTEdge, error)

GetIncomingCrossFileEdges returns edges where the target node belongs to filePath but the source node does NOT belong to filePath (cross-file incoming references).

func (*Store) GetLatestStoredCommitHash

func (s *Store) GetLatestStoredCommitHash() (string, error)

GetLatestStoredCommitHash returns the most recent commit hash stored in git_commits. Returns empty string if no commits stored.

func (*Store) GetNode

func (s *Store) GetNode(nodeID string) (*types.ASTNode, error)

GetNode retrieves a single node by ID

func (*Store) GetNodeByName

func (s *Store) GetNodeByName(symbolName string) (*types.ASTNode, error)

GetNodeByName retrieves a node by symbol name (exact match)

func (*Store) GetNodeIDsByFile

func (s *Store) GetNodeIDsByFile(filePath string) ([]string, error)

GetNodeIDsByFile retrieves all node IDs for a given file path. Used for incremental graph updates: remove old nodes before adding new ones.

func (*Store) GetNodeScore

func (s *Store) GetNodeScore(nodeID string) (*types.NodeScore, error)

GetNodeScore retrieves the scores for a single node

func (*Store) GetNodesByFile

func (s *Store) GetNodesByFile(filePath string) ([]types.ASTNode, error)

GetNodesByFile returns all nodes for a given file path

func (*Store) GetProjectSummary

func (s *Store) GetProjectSummary(project string) (*types.ProjectSummary, error)

GetProjectSummary retrieves a project summary by project name

func (*Store) GetRepoSnapshot

func (s *Store) GetRepoSnapshot(repoRoot string) (*gitmeta.RepoSnapshot, error)

GetRepoSnapshot returns the stored git snapshot for the given repo root.

func (*Store) GetSymbolIndex

func (s *Store) GetSymbolIndex() (map[string]string, error)

GetSymbolIndex returns a map of symbol_name -> node_id for symbols used in cross-file edge resolution during incremental re-index. It includes type nodes plus functions/methods, and also adds a best-effort bare-method alias (e.g. "Controller.handle" -> "handle") when the alias is not already claimed by another symbol.

func (*Store) HasVecTable

func (s *Store) HasVecTable() bool

HasVecTable returns whether the sqlite-vec virtual table is available

func (*Store) RawQuery

func (s *Store) RawQuery(query string) ([]map[string]interface{}, error)

RawQuery executes a read-only SQL query and returns results as maps. Only SELECT statements are allowed to prevent SQL injection.

func (*Store) SchemaVersion

func (s *Store) SchemaVersion() (int, error)

SchemaVersion returns the current schema version (exported for testing)

func (*Store) SearchLexical

func (s *Store) SearchLexical(query string, limit int) ([]types.SearchResult, error)

SearchLexical performs FTS5 BM25 lexical search

func (*Store) SearchLexicalByType

func (s *Store) SearchLexicalByType(query string, nodeType types.NodeType, limit int) ([]types.SearchResult, error)

SearchLexicalByType performs FTS5 BM25 search filtered to a specific node type. Used for route-specific candidate injection when query intent indicates routes.

func (*Store) SearchLexicalFilteredRaw

func (s *Store) SearchLexicalFilteredRaw(query string, nodeTypes []types.NodeType, limit int) ([]types.SearchResult, error)

SearchLexicalFilteredRaw performs FTS5 BM25 search filtered to specific node types. Like SearchLexicalRaw but adds WHERE n.node_type IN (...) filter. Used to exclude route nodes from general FTS (routes are found via edge-based lookup).

func (*Store) SearchLexicalRaw

func (s *Store) SearchLexicalRaw(query string, limit int) ([]types.SearchResult, error)

SearchLexicalRaw performs FTS5 BM25 lexical search without sanitizing the query. Use this when the caller has already constructed a valid FTS5 query (e.g., with boolean operators like OR and prefix wildcards like *). For untrusted user input, use SearchLexical instead which sanitizes automatically.

func (*Store) SearchNodesByName

func (s *Store) SearchNodesByName(pattern string) ([]types.ASTNode, error)

SearchNodesByName searches for nodes whose symbol_name contains the given pattern (case-insensitive)

func (*Store) SearchSemantic

func (s *Store) SearchSemantic(queryEmbedding []float32, limit int) ([]types.SearchResult, error)

SearchSemantic performs KNN semantic search using sqlite-vec. Returns nil, nil (empty results, no error) if sqlite-vec is not available, enabling graceful degradation to lexical-only search.

func (*Store) UpdateFTS

func (s *Store) UpdateFTS(node types.ASTNode) error

UpdateFTS updates the FTS index for a node. Wrapped in a transaction so DELETE+INSERT are atomic — if INSERT fails, the old entry is preserved.

func (*Store) UpsertEdge

func (s *Store) UpsertEdge(edge types.ASTEdge) error

UpsertEdge inserts or ignores an edge in the database

func (*Store) UpsertEdges

func (s *Store) UpsertEdges(edges []types.ASTEdge) error

UpsertEdges batch-inserts edges using a transaction

func (*Store) UpsertEmbedding

func (s *Store) UpsertEmbedding(nodeID string, embedding []float32) error

UpsertEmbedding stores a vector embedding for a node. The embedding dimension must match the configured store dimension. Returns nil (no-op) if sqlite-vec is not available, enabling graceful degradation. Wrapped in a transaction to ensure delete + insert are atomic.

func (*Store) UpsertFileHistory

func (s *Store) UpsertFileHistory(changes []gitmeta.FileChange) error

UpsertFileHistory stores file-commit associations in batch.

func (*Store) UpsertFileIntents

func (s *Store) UpsertFileIntents(intents []gitmeta.FileIntent) error

UpsertFileIntents stores compacted file intent summaries in batch.

func (*Store) UpsertGitCommits

func (s *Store) UpsertGitCommits(commits []gitmeta.CommitInfo) error

UpsertGitCommits stores commit metadata in batch.

func (*Store) UpsertNode

func (s *Store) UpsertNode(node types.ASTNode) error

UpsertNode inserts or updates a node in the database. Uses ON CONFLICT to avoid DELETE+INSERT which would cascade-delete edges. Wrapped in a transaction to ensure node + FTS index stay in sync.

func (*Store) UpsertNodeScores

func (s *Store) UpsertNodeScores(scores []types.NodeScore) error

UpsertNodeScores batch-inserts node scores using a transaction

func (*Store) UpsertNodes

func (s *Store) UpsertNodes(nodes []types.ASTNode) error

UpsertNodes batch-inserts nodes using a transaction

func (*Store) UpsertProjectSummary

func (s *Store) UpsertProjectSummary(summary types.ProjectSummary) error

UpsertProjectSummary inserts or updates a project summary

func (*Store) UpsertRepoSnapshot

func (s *Store) UpsertRepoSnapshot(snap gitmeta.RepoSnapshot) error

UpsertRepoSnapshot stores or updates the repository git snapshot.

Jump to

Keyboard shortcuts

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