storage

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CosineSimilarity

func CosineSimilarity(a, b []float32) float32

CosineSimilarity calculates the similarity between two vectors.

Types

type DB

type DB struct {
	MaxMemMB int
	// contains filtered or unexported fields
}

DB represents the SQLite storage engine.

func NewDB

func NewDB(dbPath string) (*DB, error)

NewDB opens (or creates) a SQLite database at the specified path.

func (*DB) BeginTx

func (db *DB) BeginTx() (*sql.Tx, error)

BeginTx starts a transaction.

func (*DB) CheckMemoryLimit

func (db *DB) CheckMemoryLimit()

CheckMemoryLimit checks if the current heap allocation exceeds the soft limit and hints the GC to run if necessary.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) GetAllVectors

func (db *DB) GetAllVectors() ([]VectorEntry, error)

GetAllVectors returns all stored vectors along with chunk content for matching.

func (*DB) GetChunkDetails

func (db *DB) GetChunkDetails(chunkID int64) (path string, content string, index int, err error)

GetChunkDetails returns the text content and file path for a chunk ID.

func (*DB) SaveChunk

func (db *DB) SaveChunk(docID int64, index int, content string) (int64, error)

SaveChunk inserts a chunk (non-transactional).

func (*DB) SaveChunkTx

func (db *DB) SaveChunkTx(tx *sql.Tx, docID int64, index int, content string) (int64, error)

SaveChunkTx inserts a chunk using an existing transaction.

func (*DB) SaveDocument

func (db *DB) SaveDocument(path, filename string) (int64, error)

SaveDocument inserts a document and returns its ID. It deletes any existing document with the same path to ensure all related chunks and vectors are purged via ON DELETE CASCADE.

func (*DB) SaveVector

func (db *DB) SaveVector(chunkID int64, embedding []float32) error

SaveVector inserts a vector (non-transactional).

func (*DB) SaveVectorTx

func (db *DB) SaveVectorTx(tx *sql.Tx, chunkID int64, embedding []float32) error

SaveVectorTx inserts a vector using an existing transaction.

func (*DB) TruncateDB

func (db *DB) TruncateDB() error

TruncateDB clears all data from the database.

type SearchResult

type SearchResult struct {
	Path    string
	Content string
	Index   int
	Score   float32
}

SearchResult represents a single match from a vector search.

type VectorEntry

type VectorEntry struct {
	ChunkID   int64
	Embedding []float32
	Content   string
}

VectorEntry holds a chunk's ID and its embedding for matching.

Jump to

Keyboard shortcuts

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