store

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendStatus added in v1.0.0

type BackendStatus struct {
	Type    string `json:"type"`    // Backend type (e.g., "gob", "postgres")
	Host    string `json:"host"`    // Backend host/path (e.g., "localhost", "/path/to/index")
	Name    string `json:"name"`    // Backend name (e.g., database name, index name)
	Healthy bool   `json:"healthy"` // true if backend is reachable and operational
}

BackendStatus represents the status of a storage backend

type Chunk

type Chunk struct {
	ID        string    `json:"id"`
	FilePath  string    `json:"file_path"`
	StartLine int       `json:"start_line"`
	EndLine   int       `json:"end_line"`
	Content   string    `json:"content"`
	Hash      string    `json:"hash"`
	UpdatedAt time.Time `json:"updated_at"`
}

Chunk represents a piece of code with its embedding

type CodeStore added in v1.0.0

type CodeStore interface {
	// SaveChunks stores multiple chunks atomically
	SaveChunks(ctx context.Context, chunks []Chunk) error

	// DeleteByFile removes all chunks for a given file path
	DeleteByFile(ctx context.Context, filePath string) error

	// GetDocument retrieves document metadata by path
	GetDocument(ctx context.Context, filePath string) (*Document, error)

	// SaveDocument stores document metadata
	SaveDocument(ctx context.Context, doc Document) error

	// DeleteDocument removes document metadata
	DeleteDocument(ctx context.Context, filePath string) error

	// ListDocuments returns all indexed document paths
	ListDocuments(ctx context.Context) ([]string, error)

	// Close cleanly shuts down the store
	Close() error

	// GetStats returns index statistics
	GetStats(ctx context.Context) (*IndexStats, error)

	// ListFilesWithStats returns all files with their chunk counts
	ListFilesWithStats(ctx context.Context) ([]FileStats, error)

	// GetChunksForFile returns all chunks for a specific file
	GetChunksForFile(ctx context.Context, filePath string) ([]Chunk, error)

	// GetAllChunks returns all chunks in the store (used for text search)
	GetAllChunks(ctx context.Context) ([]Chunk, error)
}

CodeStore defines the interface for code storage backends

type Document

type Document struct {
	Path     string    `json:"path"`
	Hash     string    `json:"hash"`
	ModTime  time.Time `json:"mod_time"`
	ChunkIDs []string  `json:"chunk_ids"`
}

Document represents a file with its chunks

type FTSSearcher

type FTSSearcher interface {
	SearchFTS(ctx context.Context, query string, limit int) ([]SearchResult, error)
}

FTSSearcher is an interface for stores that support full-text search

type FileStats

type FileStats struct {
	Path       string    `json:"path"`
	ChunkCount int       `json:"chunk_count"`
	ModTime    time.Time `json:"mod_time"`
}

FileStats contains statistics for a single file

type IndexStats

type IndexStats struct {
	TotalFiles  int       `json:"total_files"`
	TotalChunks int       `json:"total_chunks"`
	IndexSize   int64     `json:"index_size"` // bytes
	LastUpdated time.Time `json:"last_updated"`
}

IndexStats contains statistics about the index

type PostgresFTSStore

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

PostgresFTSStore implements CodeStore using PostgreSQL Full Text Search. It uses pg_textsearch extension for true BM25 ranking when available, falling back to ts_rank with 'simple' configuration for code content.

func NewPostgresFTSStore

func NewPostgresFTSStore(ctx context.Context, dsn string, projectID string) (*PostgresFTSStore, error)

NewPostgresFTSStore creates a new PostgresFTSStore with FTS support

func (*PostgresFTSStore) BackendStatus added in v1.0.0

func (s *PostgresFTSStore) BackendStatus(ctx context.Context) *BackendStatus

BackendStatus returns the backend status

func (*PostgresFTSStore) Close

func (s *PostgresFTSStore) Close() error

Close closes the database connection pool

func (*PostgresFTSStore) DeleteByFile

func (s *PostgresFTSStore) DeleteByFile(ctx context.Context, filePath string) error

DeleteByFile removes all chunks for a given file path

func (*PostgresFTSStore) DeleteDocument

func (s *PostgresFTSStore) DeleteDocument(ctx context.Context, filePath string) error

DeleteDocument removes document metadata

func (*PostgresFTSStore) GetAllChunks

func (s *PostgresFTSStore) GetAllChunks(ctx context.Context) ([]Chunk, error)

GetAllChunks returns all chunks in the store

func (*PostgresFTSStore) GetAllProjects added in v1.0.0

func (s *PostgresFTSStore) GetAllProjects(ctx context.Context) ([]ProjectInfo, error)

GetAllProjects returns all unique project IDs with their file counts.

func (*PostgresFTSStore) GetChunksForFile

func (s *PostgresFTSStore) GetChunksForFile(ctx context.Context, filePath string) ([]Chunk, error)

GetChunksForFile returns all chunks for a specific file

func (*PostgresFTSStore) GetDocument

func (s *PostgresFTSStore) GetDocument(ctx context.Context, filePath string) (*Document, error)

GetDocument retrieves document metadata by path

func (*PostgresFTSStore) GetStats

func (s *PostgresFTSStore) GetStats(ctx context.Context) (*IndexStats, error)

GetStats returns index statistics

func (*PostgresFTSStore) ListDocuments

func (s *PostgresFTSStore) ListDocuments(ctx context.Context) ([]string, error)

ListDocuments returns all indexed document paths

func (*PostgresFTSStore) ListFilesWithStats

func (s *PostgresFTSStore) ListFilesWithStats(ctx context.Context) ([]FileStats, error)

ListFilesWithStats returns all files with their chunk counts

func (*PostgresFTSStore) Pool added in v1.0.0

func (s *PostgresFTSStore) Pool() *pgxpool.Pool

Pool returns the underlying connection pool for custom queries.

func (*PostgresFTSStore) ProjectID added in v1.0.0

func (s *PostgresFTSStore) ProjectID() string

ProjectID returns the current project ID.

func (*PostgresFTSStore) SaveChunks

func (s *PostgresFTSStore) SaveChunks(ctx context.Context, chunks []Chunk) error

SaveChunks stores multiple chunks with tsvector data

func (*PostgresFTSStore) SaveDocument

func (s *PostgresFTSStore) SaveDocument(ctx context.Context, doc Document) error

SaveDocument stores document metadata

func (*PostgresFTSStore) SearchFTS

func (s *PostgresFTSStore) SearchFTS(ctx context.Context, query string, limit int) ([]SearchResult, error)

SearchFTS performs full-text search using the query text directly. When pg_textsearch is available, it uses true BM25 ranking via the <@> operator. Otherwise, it falls back to ts_rank with normalization.

type ProjectInfo added in v1.0.0

type ProjectInfo struct {
	ID        string `json:"id"`
	FileCount int    `json:"file_count"`
}

ProjectInfo contains information about an indexed project.

type SearchResult

type SearchResult struct {
	Chunk Chunk   `json:"chunk"`
	Score float32 `json:"score"`
}

SearchResult represents a search match with its relevance score

type StatusProvider added in v1.0.0

type StatusProvider interface {
	BackendStatus(ctx context.Context) *BackendStatus
}

StatusProvider is an optional interface for backends that can report their status

Jump to

Keyboard shortcuts

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