Documentation
¶
Index ¶
- Constants
- func EnsureVecWASM()
- type Index
- func (i *Index) All(ctx context.Context, yield func(model.SectionID) bool) error
- func (i *Index) DeleteByID(ctx context.Context, ids ...model.SectionID) error
- func (i *Index) DeleteBySource(ctx context.Context, source *url.URL) error
- func (i *Index) GenerateSnapshot(ctx context.Context) (io.ReadCloser, error)
- func (i *Index) Index(ctx context.Context, document model.Document, funcs ...index.OptionFunc) error
- func (i *Index) RestoreSnapshot(ctx context.Context, r io.Reader) error
- func (i *Index) Search(ctx context.Context, query string, opts index.SearchOptions) ([]*index.SearchResult, error)
- func (i *Index) Semantic() bool
- type OptionFunc
- type Options
- type SnapshottedMetadata
- type SnapshottedRecord
Constants ¶
const DefaultMaxWords int = 500
DefaultMaxWords bounds, by default, the number of words per chunk sent to the embeddings model.
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 ¶
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) DeleteByID ¶
DeleteByID implements index.Index.
func (*Index) DeleteBySource ¶
DeleteBySource implements index.Index.
func (*Index) GenerateSnapshot ¶
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 ¶
RestoreSnapshot implements snapshot.Snapshotable.
type OptionFunc ¶ added in v0.0.2
type OptionFunc func(opts *Options)
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
}
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
}