store

package
v0.0.0-...-16efc32 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOrCreateProjectWithPool

func GetOrCreateProjectWithPool(ctx context.Context, pool *pgxpool.Pool, name string, localPath string, projectID string) (string, error)

GetOrCreateProjectWithPool finds or creates a project using a raw pool connection. This is useful when you need to register a project before creating a PostgresStore. If projectID is provided, it will be used for new projects instead of generating one.

func NewPostgresPool

func NewPostgresPool(ctx context.Context, dsn string) (*pgxpool.Pool, error)

NewPostgresPool creates a new connection pool without initializing a full store. This is useful for operations that need database access before store creation.

func RunMigrations

func RunMigrations(ctx context.Context, pool *pgxpool.Pool) error

RunMigrations executes all pending SQL migrations in order. Migrations are embedded from the migrations/ directory.

func SanitizeCollectionName

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"`
	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 File

type File struct {
	ID           string    `json:"id"`
	ProjectID    string    `json:"project_id"`
	RelativePath string    `json:"relative_path"`
	Language     string    `json:"language,omitempty"`
	ContentHash  string    `json:"content_hash"`
	LineCount    int       `json:"line_count"`
	ModTime      time.Time `json:"mod_time"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

File represents a file within a project.

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 FileStore

type FileStore interface {
	// CreateFile creates a new file record.
	CreateFile(ctx context.Context, f *File) error

	// GetFile retrieves a file by project ID and relative path.
	GetFile(ctx context.Context, projectID, relativePath string) (*File, error)

	// UpdateFile updates an existing file record.
	UpdateFile(ctx context.Context, f *File) error

	// DeleteFile removes a file record.
	DeleteFile(ctx context.Context, projectID, relativePath string) error

	// ListFiles returns all files for a project.
	ListFiles(ctx context.Context, projectID string) ([]*File, error)

	// DeleteFilesByProject removes all files for a project.
	DeleteFilesByProject(ctx context.Context, projectID string) error
}

FileStore defines the interface for file management operations.

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

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

func (*GOBStore) GetChunksForFile

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

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

func (*GOBStore) ListDocuments

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

func (*GOBStore) ListFilesWithStats

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

func (*GOBStore) Load

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

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) ([]SearchResult, error)

func (*GOBStore) Stats

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

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 IndexStatus

type IndexStatus string

IndexStatus represents the current indexing state of a project.

const (
	IndexStatusPending  IndexStatus = "pending"
	IndexStatusIndexing IndexStatus = "indexing"
	IndexStatusReady    IndexStatus = "ready"
	IndexStatusError    IndexStatus = "error"
)

type PostgresProjectStore

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

PostgresProjectStore implements ProjectStore and FileStore for PostgreSQL.

func NewPostgresProjectStore

func NewPostgresProjectStore(pool *pgxpool.Pool) *PostgresProjectStore

NewPostgresProjectStore creates a new PostgresProjectStore.

func (*PostgresProjectStore) CreateFile

func (s *PostgresProjectStore) CreateFile(ctx context.Context, f *File) error

CreateFile creates a new file record.

func (*PostgresProjectStore) CreateProject

func (s *PostgresProjectStore) CreateProject(ctx context.Context, p *Project) error

CreateProject creates a new project in the store.

func (*PostgresProjectStore) DeleteFile

func (s *PostgresProjectStore) DeleteFile(ctx context.Context, projectID, relativePath string) error

DeleteFile removes a file record.

func (*PostgresProjectStore) DeleteFilesByProject

func (s *PostgresProjectStore) DeleteFilesByProject(ctx context.Context, projectID string) error

DeleteFilesByProject removes all files for a project.

func (*PostgresProjectStore) DeleteProject

func (s *PostgresProjectStore) DeleteProject(ctx context.Context, name string) error

DeleteProject removes a project and all its associated data.

func (*PostgresProjectStore) GetFile

func (s *PostgresProjectStore) GetFile(ctx context.Context, projectID, relativePath string) (*File, error)

GetFile retrieves a file by project ID and relative path.

func (*PostgresProjectStore) GetOrCreateProject

func (s *PostgresProjectStore) GetOrCreateProject(ctx context.Context, name, localPath string) (*Project, error)

GetOrCreateProject retrieves a project by name or creates it if it doesn't exist.

func (*PostgresProjectStore) GetProject

func (s *PostgresProjectStore) GetProject(ctx context.Context, name string) (*Project, error)

GetProject retrieves a project by its name.

func (*PostgresProjectStore) GetProjectByID

func (s *PostgresProjectStore) GetProjectByID(ctx context.Context, id string) (*Project, error)

GetProjectByID retrieves a project by its ID.

func (*PostgresProjectStore) ListFiles

func (s *PostgresProjectStore) ListFiles(ctx context.Context, projectID string) ([]*File, error)

ListFiles returns all files for a project.

func (*PostgresProjectStore) ListProjects

func (s *PostgresProjectStore) ListProjects(ctx context.Context) ([]*Project, error)

ListProjects returns all projects in the store.

func (*PostgresProjectStore) SetProjectStatus

func (s *PostgresProjectStore) SetProjectStatus(ctx context.Context, name string, status IndexStatus, lastError string) error

SetProjectStatus updates the index status and optional error message.

func (*PostgresProjectStore) UpdateFile

func (s *PostgresProjectStore) UpdateFile(ctx context.Context, f *File) error

UpdateFile updates an existing file record.

func (*PostgresProjectStore) UpdateProject

func (s *PostgresProjectStore) UpdateProject(ctx context.Context, p *Project) error

UpdateProject updates an existing project.

func (*PostgresProjectStore) UpdateProjectStats

func (s *PostgresProjectStore) UpdateProjectStats(ctx context.Context, name string) error

UpdateProjectStats recalculates and updates project statistics.

type PostgresStore

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

func NewPostgresStore

func NewPostgresStore(ctx context.Context, dsn string, projectUUID 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

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

func (*PostgresStore) GetChunksForFile

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) GetOrCreateProject

func (s *PostgresStore) GetOrCreateProject(ctx context.Context, name string, localPath string, projectID string) (string, error)

GetOrCreateProject finds a project by name or creates it if not found. If the project exists but local_path differs, it updates the path. If projectID is provided, it will be used for new projects instead of generating one. Returns the project UUID.

func (*PostgresStore) GetStats

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

func (*PostgresStore) ListDocuments

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

func (*PostgresStore) ListFilesWithStats

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

func (*PostgresStore) Load

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

func (*PostgresStore) Persist

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

func (*PostgresStore) Pool

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

Pool returns the underlying connection pool for use by other stores.

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) ([]SearchResult, error)

func (*PostgresStore) UpdateProjectStats

func (s *PostgresStore) UpdateProjectStats(ctx context.Context, projectUUID string) error

UpdateProjectStats updates file_count, chunk_count, and sets status to 'ready'.

type Project

type Project struct {
	ID            string      `json:"id"`
	Name          string      `json:"name"`
	LocalPath     string      `json:"local_path,omitempty"`
	Languages     []string    `json:"languages,omitempty"`
	Framework     string      `json:"framework,omitempty"`
	FileCount     int         `json:"file_count"`
	ChunkCount    int         `json:"chunk_count"`
	SymbolCount   int         `json:"symbol_count"`
	IndexStatus   IndexStatus `json:"index_status"`
	LastError     string      `json:"last_error,omitempty"`
	CreatedAt     time.Time   `json:"created_at"`
	UpdatedAt     time.Time   `json:"updated_at"`
	LastIndexedAt *time.Time  `json:"last_indexed_at,omitempty"`
}

Project represents a code project in the system.

type ProjectStore

type ProjectStore interface {
	// CreateProject creates a new project in the store.
	CreateProject(ctx context.Context, p *Project) error

	// GetProject retrieves a project by its name.
	GetProject(ctx context.Context, name string) (*Project, error)

	// GetProjectByID retrieves a project by its ID.
	GetProjectByID(ctx context.Context, id string) (*Project, error)

	// UpdateProject updates an existing project.
	UpdateProject(ctx context.Context, p *Project) error

	// DeleteProject removes a project and all its associated data.
	DeleteProject(ctx context.Context, name string) error

	// ListProjects returns all projects in the store.
	ListProjects(ctx context.Context) ([]*Project, error)

	// UpdateProjectStats recalculates and updates project statistics.
	UpdateProjectStats(ctx context.Context, name string) error

	// SetProjectStatus updates the index status and optional error message.
	SetProjectStatus(ctx context.Context, name string, status IndexStatus, lastError string) error
}

ProjectStore defines the interface for project management operations.

type QdrantStore

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

func NewQdrantStore

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

func (*QdrantStore) Close

func (s *QdrantStore) Close() error

func (*QdrantStore) DeleteByFile

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

func (*QdrantStore) DeleteDocument

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

func (*QdrantStore) GetAllChunks

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

func (*QdrantStore) GetChunksForFile

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

func (*QdrantStore) GetDocument

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

func (*QdrantStore) GetStats

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

func (*QdrantStore) ListDocuments

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

func (*QdrantStore) ListFilesWithStats

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

func (*QdrantStore) Load

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

func (*QdrantStore) Persist

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

func (*QdrantStore) SaveChunks

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

func (*QdrantStore) SaveDocument

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

func (*QdrantStore) Search

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

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) ([]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