Files
wehub-resource-sync f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:36 +08:00

52 lines
1.6 KiB
Go

package vector
import (
"context"
"database/sql"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
kitvec "go.kenn.io/kit/vector"
"go.kenn.io/kit/vector/sqlitevec"
)
func TestKitSqlitevecRoundTrip(t *testing.T) {
sqlitevec.Register()
db, err := sql.Open(vectorDriverName, vectorDSN(filepath.Join(t.TempDir(), "v.db"), false))
require.NoError(t, err)
defer db.Close()
ctx := context.Background()
_, err = db.ExecContext(ctx, `CREATE TABLE docs (
doc_key TEXT PRIMARY KEY, content TEXT NOT NULL,
content_hash TEXT NOT NULL, embed_gen TEXT)`)
require.NoError(t, err)
store, err := sqlitevec.New[string, string](ctx, db, sqlitevec.Schema{
DocsTable: "docs", IDColumn: "doc_key", ContentColumn: "content",
EmbedGenColumn: "embed_gen", RevisionColumn: "content_hash",
VectorsPrefix: "docs_vectors",
})
require.NoError(t, err)
gen := kitvec.Generation{Model: "fake", Dimensions: 3}
fp := gen.Fingerprint()
require.NoError(t, store.EnsureGeneration(ctx, fp, gen, sqlitevec.StateActive))
_, err = db.ExecContext(ctx,
`INSERT INTO docs VALUES ('d1', 'hello world', 'h1', NULL)`)
require.NoError(t, err)
enc := func(_ context.Context, texts []string) ([][]float32, error) {
out := make([][]float32, len(texts))
for i := range texts {
out[i] = []float32{1, 0, 0}
}
return out, nil
}
stats, err := kitvec.Fill[string, string](ctx, store, fp, enc,
kitvec.FillOptions[string]{})
require.NoError(t, err)
require.Equal(t, 1, stats.Documents)
hits, err := store.QueryGeneration(ctx, fp, kitvec.Vector{1, 0, 0}, 5)
require.NoError(t, err)
require.Len(t, hits, 1)
require.Equal(t, "d1", hits[0].Doc)
}