Vectors

A VECTOR field stores a fixed-length list of numbers, usually an embedding: the output of a model that turns a text, an image or a product into numbers, so that similar things get similar vectors. DianaDB stores the vectors next to the rest of the document and finds the documents whose vectors are closest to a query vector.

What it is for

  • Semantic search: find documents by meaning, not by exact words ("my order never arrived" finds "delivery delayed").
  • Recommendations: products, articles or users similar to the one being viewed.
  • Duplicate detection: near-identical support tickets, listings or images.
  • Memory for AI agents (RAG): fetch the passages closest to a question and give them to a language model.

Quick example

import { DianaDb, Model, Types } from '@diana-db/odm';

const articleModel = new Model({
  database: 'blog',
  collection: 'article',
  name: 'Article',
  schema: {
    title: { type: Types.STRING, required: true },
    embedding: { type: Types.VECTOR, dimensions: 384, required: true },
  },
});

// embedding: an array of 384 numbers from your embedding model
await articleModel.insert({ title: 'Why columnar storage is fast', embedding });

// the 5 articles closest in meaning to the question
const found = await articleModel.find([
  { embedding: { $neighbors: { vector: questionEmbedding, count: 5, metric: 'cosine' } } },
]);

In this section

When a dedicated vector database fits better

The search is exact: every vector of the field is compared with the query. That gives the true nearest documents and needs no index tuning, and it is fast enough for up to a few hundred thousand vectors per field. For tens of millions of vectors, approximate indexes (as in Qdrant, Milvus or pgvector with HNSW) answer faster. See Performance and Limits.