db

package
v0.12.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEmbeddingBlob

func ValidateEmbeddingBlob(blob []byte, dimension int) error

ValidateEmbeddingBlob validates a little-endian float32 vector against its metadata dimension without allocating. It is shared by health checks and repair selection so both agree on what can safely participate in search.

Types

type DB

type DB struct {
	*sql.DB
}

DB wraps a *sql.DB with qi-specific helpers.

func Open

func Open(ctx context.Context, path string) (*DB, error)

Open opens (or creates) the qi SQLite database at path, runs migrations, and configures WAL mode.

func (*DB) DeleteCollection

func (db *DB) DeleteCollection(ctx context.Context, name string) error

DeleteCollection removes all data associated with the given collection name: chunk vectors, embeddings, chunks (FTS triggers keep chunks_fts in sync), documents, and index runs. Orphaned content blobs (not referenced by any remaining document) are also pruned.

func (*DB) EmbeddingHealth

func (db *DB) EmbeddingHealth(ctx context.Context, fingerprint string, dimension int, collection string) (EmbeddingHealth, error)

func (*DB) InsertEmbedding

func (db *DB) InsertEmbedding(ctx context.Context, chunkID int64, embedding []float32) error

InsertEmbedding stores a vector embedding for a chunk as a raw BLOB. Retained for tests that only need a vector row without metadata.

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

Ping verifies the database connection.

func (*DB) RenameCollectionData

func (db *DB) RenameCollectionData(ctx context.Context, oldName, newName string) error

RenameCollectionData merges indexed data from oldName into newName.

A document is a duplicate only when the destination holds the same relative path AND the same content hash — that is, genuinely the same file indexed under both names. Matching on path alone would delete real documents whenever the destination name happened to be occupied by a different directory that shares a filename, which basename-derived collection names make easy to hit. Documents that cannot move without overwriting a different file are left under oldName, where they stay searchable and can be removed deliberately.

func (*DB) RenameCollections

func (db *DB) RenameCollections(ctx context.Context, renames [][2]string) error

RenameCollections applies a whole set of {old, new} renames in one transaction. Renames are staged through temporary names first, because one collection's old name can be another's new name ("x-foo" -> "foo" alongside "y-x-foo" -> "x-foo"); renaming those in place would merge unrelated documents into whichever name happened to still be occupied.

func (*DB) UpsertEmbedding

func (db *DB) UpsertEmbedding(ctx context.Context, chunkID int64, embedding []float32, provider, model string, dimension int, fingerprint string) error

UpsertEmbedding stores a chunk's vector and its embedding metadata (provider, model, dimension, fingerprint) atomically in one transaction, so a vector can never persist without matching metadata (or vice versa).

type EmbeddingHealth

type EmbeddingHealth struct {
	Current  int
	Missing  int
	Stale    int
	Orphaned int
}

EmbeddingHealth partitions active chunks into mutually exclusive states. Orphaned means one side is absent or the vector/metadata pair is invalid.

Jump to

Keyboard shortcuts

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