SIMD-accelerated vector similarity search for Sharc. Zero-copy BLOB decode, cosine/euclidean/dot product distance via TensorPrimitives, top-K nearest neighbor with metadata pre-filtering.
$ dotnet add package Sharc.VectorSIMD-accelerated vector similarity search for Sharc.
MemoryMarshal.Cast<byte, float> directly on cached page buffersTensorPrimitives (AVX-512 when available)using Sharc;
using Sharc.Vector;
using var db = SharcDatabase.Open("knowledge.db");
// Create a reusable vector search handle
using var vq = db.Vector("documents", "embedding", DistanceMetric.Cosine);
// Optional: metadata pre-filter (applied before distance computation)
vq.Where(FilterStar.Column("category").Eq("science"));
// Find the 10 nearest neighbors
float[] queryVector = GetEmbedding("How do quantum computers work?");
var results = vq.NearestTo(queryVector, k: 10);
foreach (var match in results.Matches)
Console.WriteLine($"Row {match.RowId}: distance={match.Distance:F4}");
Vectors are stored as BLOB columns in regular SQLite tables:
byte[] vectorBlob = BlobVectorCodec.Encode(embeddingModel.Encode("Hello world"));
// Store vectorBlob as a BLOB column value via SharcWriter
| Operation | Allocation | Notes |
|---|---|---|
| Per-row distance | 0 B | Zero-copy BLOB → float reinterpret |
| 10K vectors (384-dim) | ~5-10 ms | TensorPrimitives SIMD |
| 100K vectors (384-dim) | ~50-100 ms | Linear scan baseline |
System.Numerics.Tensors (included automatically)