Skip to content

Vector Search

Tom Laird-McConnell edited this page May 11, 2026 · 1 revision

Vector Similarity Search

LottaDB supports vector similarity search using embeddings. Mark string properties with QueryableMode.Vector and LottaDB will automatically generate embeddings at index time and support .Similar() queries for semantic search.

By default, LottaDB uses ElBruno.LocalEmbeddings with the SmartComponents/bge-micro-v2 model -- no external API calls needed. You can override this by setting EmbeddingGenerator on the catalog.

Making a property vector-searchable

Attribute-based:

public class Article
{
    [Key]
    public string Id { get; set; } = "";

    [Queryable(Vector = true)]                              // analyzed (default) + vector
    public string Title { get; set; } = "";

    [Queryable(Vector = true)]
    public string Body { get; set; } = "";

    [Queryable(QueryableMode.NotAnalyzed, Vector = true)]   // exact match + vector
    public string Slug { get; set; } = "";

    [Queryable]                                              // full-text only, no embeddings
    public string Category { get; set; } = "";
}

Fluent:

config.Store<Article>(s =>
{
    s.SetKey(a => a.Id);
    s.AddQueryable(a => a.Title).Vector();              // analyzed + vector
    s.AddQueryable(a => a.Body).Vector();
    s.AddQueryable(a => a.Slug).NotAnalyzed().Vector(); // exact match + vector
    s.AddQueryable(a => a.Category);                     // full-text only
});

Vector is composable with any QueryableMode -- it adds vector embeddings on top of whatever analysis mode you choose.

Querying with .Similar()

Property-level -- search against a specific field's embeddings:

// Find articles with titles semantically similar to "cute cat napping"
var results = db.Search<Article>(a => a.Title.Similar("cute cat napping")).ToList();

Object-level -- search against the default search property (the _content_ composite field, or your [DefaultSearch] property):

// Semantic search across default search content
var results = db.Search<Article>(a => a.Similar("machine learning breakthroughs")).ToList();

Hybrid -- combine vector similarity with filters:

// Semantic search + exact filter
var results = db.Search<Article>(a => a.Title.Similar("furry animals") && a.Category == "pets")
    .ToList();

Limit results:

var top5 = db.Search<Article>(a => a.Similar("quantum physics"))
    .Take(5)
    .ToList();

Custom embedding generator

To use a different embedding model or an external API, set EmbeddingGenerator on the catalog:

var catalog = new LottaCatalog("myapp", connectionString, catalog =>
{
    catalog.EmbeddingGenerator = myCustomEmbeddingGenerator; // IEmbeddingGenerator<string, Embedding<float>>
});

Set EmbeddingGenerator to null to disable vector support entirely.

Clone this wiki locally