sqlitevec

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEmbeddingsConcurrency int = 8

DefaultEmbeddingsConcurrency bounds, by default, how many embedding batches are computed in parallel for a single document. 8 gives most of the speedup on large documents while staying modest enough to avoid overwhelming the embeddings endpoint (rate limiting / 429s); lower it via config for stricter endpoints.

View Source
const DefaultMaxWords int = 500

DefaultMaxWords bounds, by default, the number of words per chunk sent to the embeddings model.

View Source
const DefaultVectorSize int = 768

DefaultVectorSize is the default dimension of the vec0 embedding column, matching common 768-dimension embedding models.

Variables

This section is empty.

Functions

func EnsureVecWASM added in v0.0.3

func EnsureVecWASM()

EnsureVecWASM forces ncruces/go-sqlite3 to load the sqlite-vec-enabled WASM build, overriding any plain SQLite build that another package may have selected.

It is only needed when the same process opens a sqlite-vec index AND another ncruces/go-sqlite3 connection whose package imports the vanilla WASM build — most notably the gorm SQLite store (gorm.NewSQLiteStore), which transitively imports github.com/ncruces/go-sqlite3/embed. Both builds assign the global sqlite3.Binary from their init, so which one wins depends on undefined init order; without this call the sqlite-vec build may lose and vec0 virtual tables fail with "no such module: vec0".

Call it once at startup, before opening ANY sqlite connection (the store included). The vec0-enabled build is a superset of plain SQLite, so the store works on it unchanged. It is unnecessary when sqlite-vec is the only ncruces/go-sqlite3 user in the process.

Types

type Index

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

func NewIndex

func NewIndex(conn *sqlite3.Conn, client llm.Client, funcs ...OptionFunc) *Index

NewIndex creates a sqlite-vec backed vector index on top of the given connection. The connection remains owned by the caller. The embeddings model (WithEmbeddingsModel) and vector size (WithVectorSize) are recorded in the index on first use; reopening an existing index with a different model or size is rejected to prevent silently mixing incompatible vectors.

func (*Index) All

func (i *Index) All(ctx context.Context, yield func(model.SectionID) bool) error

All implements index.Index.

func (*Index) DeleteByID

func (i *Index) DeleteByID(ctx context.Context, ids ...model.SectionID) error

DeleteByID implements index.Index.

func (*Index) DeleteBySource

func (i *Index) DeleteBySource(ctx context.Context, source *url.URL) error

DeleteBySource implements index.Index.

func (*Index) GenerateSnapshot

func (i *Index) GenerateSnapshot(ctx context.Context) (io.ReadCloser, error)

GenerateSnapshot implements snapshot.Snapshotable.

func (*Index) Index

func (i *Index) Index(ctx context.Context, document model.Document, funcs ...index.OptionFunc) error

Index implements index.Index.

func (*Index) RestoreSnapshot

func (i *Index) RestoreSnapshot(ctx context.Context, r io.Reader) error

RestoreSnapshot implements snapshot.Snapshotable.

func (*Index) Search

func (i *Index) Search(ctx context.Context, query string, opts index.SearchOptions) ([]*index.SearchResult, error)

Search implements index.Index.

func (*Index) Semantic added in v0.0.2

func (i *Index) Semantic() bool

Semantic implements index.Semantic: sqlite-vec performs vector similarity search and therefore benefits from query expansion such as HyDE.

type OptionFunc added in v0.0.2

type OptionFunc func(opts *Options)

func WithEmbeddingsConcurrency added in v0.0.6

func WithEmbeddingsConcurrency(n int) OptionFunc

WithEmbeddingsConcurrency bounds how many embedding batches are computed in parallel for a single document (see Options.EmbeddingsConcurrency).

func WithEmbeddingsModel added in v0.0.2

func WithEmbeddingsModel(model string) OptionFunc

WithEmbeddingsModel records the embeddings model backing the index.

func WithMaxWords added in v0.0.2

func WithMaxWords(maxWords int) OptionFunc

WithMaxWords bounds the size of the chunks sent to the embeddings model.

func WithVectorSize added in v0.0.2

func WithVectorSize(size int) OptionFunc

WithVectorSize sets the dimension of the vec0 embedding column.

type Options added in v0.0.2

type Options struct {
	// EmbeddingsModel identifies the embeddings model. It is recorded in the
	// index and opening an existing index with a different model is rejected
	// (the stored vectors would no longer be comparable).
	EmbeddingsModel string
	// VectorSize is the dimension of the vec0 embedding column (default
	// DefaultVectorSize). It is recorded in the index; opening an existing
	// index with a different size is rejected.
	VectorSize int
	// MaxWords bounds the size of the chunks sent to the embeddings model.
	MaxWords int
	// EmbeddingsConcurrency bounds how many embedding batches are computed in
	// parallel for a single document. Large documents split into many batches;
	// computing them concurrently cuts indexing latency at the cost of more
	// simultaneous requests to the embeddings endpoint. Defaults to
	// DefaultEmbeddingsConcurrency when <= 0.
	EmbeddingsConcurrency int
}

Options configures a sqlite-vec Index.

func NewOptions added in v0.0.2

func NewOptions(funcs ...OptionFunc) *Options

type SnapshottedMetadata

type SnapshottedMetadata struct {
	Model string
}

type SnapshottedRecord

type SnapshottedRecord struct {
	Source      string
	SectionID   string
	Embeddings  []byte
	Collections []string
}

Directories

Path Synopsis
internal
vec

Jump to

Keyboard shortcuts

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