store

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SanitizeCollectionName added in v0.18.0

func SanitizeCollectionName(path string) string

Types

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"`
	Vector      []float32 `json:"vector"`
	Hash        string    `json:"hash"`
	ContentHash string    `json:"content_hash"` // SHA256 of raw content (path-independent)
	UpdatedAt   time.Time `json:"updated_at"`
}

Chunk represents a piece of code with its vector embedding

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 EmbeddingCache added in v0.28.0

type EmbeddingCache interface {
	// LookupByContentHash returns the embedding vector for the given content hash.
	// Returns (vector, true, nil) if found, (nil, false, nil) if not found.
	LookupByContentHash(ctx context.Context, contentHash string) ([]float32, bool, error)
}

EmbeddingCache is an optional interface that VectorStore implementations can provide to enable content-addressed embedding deduplication. When a store implements this interface, the indexer will look up existing embeddings by content hash before calling the embedder, avoiding redundant API calls for identical content (e.g., across git worktrees).

type FileStats added in v0.2.0

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 GOBStore

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

func NewGOBStore

func NewGOBStore(indexPath string) *GOBStore

func (*GOBStore) Close

func (s *GOBStore) Close() error

func (*GOBStore) DeleteByFile

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

func (*GOBStore) DeleteDocument

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

func (*GOBStore) GetAllChunks added in v0.3.0

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

func (*GOBStore) GetChunksForFile added in v0.2.0

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

func (*GOBStore) GetDocument

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

func (*GOBStore) GetStats added in v0.2.0

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

func (*GOBStore) ListDocuments

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

func (*GOBStore) ListFilesWithStats added in v0.2.0

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

func (*GOBStore) Load

func (s *GOBStore) Load(ctx context.Context) error

func (*GOBStore) LookupByContentHash added in v0.28.0

func (s *GOBStore) LookupByContentHash(ctx context.Context, contentHash string) ([]float32, bool, error)

LookupByContentHash searches in-memory chunks for a matching content hash.

func (*GOBStore) Persist

func (s *GOBStore) Persist(ctx context.Context) error

func (*GOBStore) SaveChunks

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

func (*GOBStore) SaveDocument

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

func (*GOBStore) Search

func (s *GOBStore) Search(ctx context.Context, queryVector []float32, limit int, opts SearchOptions) ([]SearchResult, error)

func (*GOBStore) Stats

func (s *GOBStore) Stats() (numDocs int, numChunks int)

type IndexStats added in v0.2.0

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 PostgresStore

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

func NewPostgresStore

func NewPostgresStore(ctx context.Context, dsn string, projectID string, vectorDimensions int) (*PostgresStore, error)

func (*PostgresStore) Close

func (s *PostgresStore) Close() error

func (*PostgresStore) DeleteByFile

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

func (*PostgresStore) DeleteDocument

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

func (*PostgresStore) GetAllChunks added in v0.3.0

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

func (*PostgresStore) GetChunksForFile added in v0.2.0

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

func (*PostgresStore) GetDocument

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

func (*PostgresStore) GetStats added in v0.2.0

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

func (*PostgresStore) ListDocuments

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

func (*PostgresStore) ListFilesWithStats added in v0.2.0

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

func (*PostgresStore) Load

func (s *PostgresStore) Load(ctx context.Context) error

func (*PostgresStore) LookupByContentHash added in v0.28.0

func (s *PostgresStore) LookupByContentHash(ctx context.Context, contentHash string) ([]float32, bool, error)

LookupByContentHash queries the chunks table for a matching content hash and returns the vector.

func (*PostgresStore) Persist

func (s *PostgresStore) Persist(ctx context.Context) error

func (*PostgresStore) SaveChunks

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

func (*PostgresStore) SaveDocument

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

func (*PostgresStore) Search

func (s *PostgresStore) Search(ctx context.Context, queryVector []float32, limit int, opts SearchOptions) ([]SearchResult, error)

type QdrantStore added in v0.18.0

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

func NewQdrantStore added in v0.18.0

func NewQdrantStore(ctx context.Context, endpoint string, port int, useTLS bool, collection, apiKey string, dimensions int) (*QdrantStore, error)

func (*QdrantStore) Close added in v0.18.0

func (s *QdrantStore) Close() error

func (*QdrantStore) DeleteByFile added in v0.18.0

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

func (*QdrantStore) DeleteDocument added in v0.18.0

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

func (*QdrantStore) GetAllChunks added in v0.18.0

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

func (*QdrantStore) GetChunksForFile added in v0.18.0

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

func (*QdrantStore) GetDocument added in v0.18.0

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

func (*QdrantStore) GetStats added in v0.18.0

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

func (*QdrantStore) ListDocuments added in v0.18.0

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

func (*QdrantStore) ListFilesWithStats added in v0.18.0

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

func (*QdrantStore) Load added in v0.18.0

func (s *QdrantStore) Load(ctx context.Context) error

func (*QdrantStore) LookupByContentHash added in v0.28.0

func (s *QdrantStore) LookupByContentHash(ctx context.Context, contentHash string) ([]float32, bool, error)

LookupByContentHash searches Qdrant for a point matching the content hash.

func (*QdrantStore) Persist added in v0.18.0

func (s *QdrantStore) Persist(ctx context.Context) error

func (*QdrantStore) SaveChunks added in v0.18.0

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

func (*QdrantStore) SaveDocument added in v0.18.0

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

func (*QdrantStore) Search added in v0.18.0

func (s *QdrantStore) Search(ctx context.Context, queryVector []float32, limit int, opts SearchOptions) ([]SearchResult, error)

type SearchOptions added in v0.33.0

type SearchOptions struct {
	PathPrefix string
}

SearchOptions contains optional filters for vector search queries.

type SearchResult

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

SearchResult represents a search match with its relevance score

type VectorStore

type VectorStore 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

	// Search finds the most similar chunks to a query vector
	Search(ctx context.Context, queryVector []float32, limit int, opts SearchOptions) ([]SearchResult, 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)

	// Load reads the store from persistent storage
	Load(ctx context.Context) error

	// Persist writes the store to persistent storage
	Persist(ctx context.Context) 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)
}

VectorStore defines the interface for vector storage backends

Jump to

Keyboard shortcuts

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