> ## Documentation Index
> Fetch the complete documentation index at: https://docs.infino.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Embeddings

> Bring your own embeddings to Infino. Supply vectors from any model, store them alongside your data, and index them for fast kNN vector search.

Infino is **bring-your-own-embeddings**: it does not call an embedding model for you.
You compute vectors with whatever model you like, store them in a vector column, and
Infino builds the vector index over them.

## The pattern

1. Declare a fixed-width vector column whose dimension matches your model's output.
2. Declare a vector index on it with the **same dimension** and a distance **metric**.
3. Embed your text and append the vectors alongside the rows.

<CodeGroup>
  ```python Python icon="python" theme={null}
  from sentence_transformers import SentenceTransformer
  model = SentenceTransformer("all-MiniLM-L6-v2")   # 384-dim
  def embed(text): return model.encode(text).tolist()

  # dim (384) must match the model and the index spec:
  docs = db.create_table(
      "docs", schema,
      infino.IndexSpec().fts("body").vector("embedding", 384, 64, "cosine"),
  )
  docs.append([{"doc_id": "1", "body": text, "embedding": embed(text)}])
  ```

  ```typescript Node.js icon="node-js" theme={null}
  import { pipeline } from "@huggingface/transformers";
  const extractor = await pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2"); // 384-dim
  const embed = async (text) => Array.from((await extractor(text, { pooling: "mean", normalize: true })).data);

  // dim (384) must match the model and the index spec:
  const docs = db.createTable(
    "docs",
    { doc_id: "large_utf8", body: "large_utf8", embedding: { vector: 384 } },
    new IndexSpec().fts("body").vector("embedding", 384, 64, "cosine"),
  );
  docs.append([{ doc_id: "1", body: text, embedding: await embed(text) }]);
  ```

  ```rust Rust icon="rust" theme={null}
  use infino::{IndexSpec, Metric};

  // Compute embeddings with your model (e.g. via `candle`, `fastembed`, or an HTTP
  // service), then append the vectors as an Arrow RecordBatch (see the Quickstart).
  // dim (384) must match your model and the index spec:
  let spec = IndexSpec::new().fts("body").vector("embedding", 384, 64, Metric::Cosine);
  ```
</CodeGroup>

<Note>
  Embed your **queries** with the same model at search time, and pass the query vector to
  `vector_search` (see [Search](/guides/search#vector-search)).
</Note>

## Choosing a metric

Match the index metric to how your embeddings are produced:

| Metric   | Use when                                                                |
| -------- | ----------------------------------------------------------------------- |
| `cosine` | embeddings are normalized (most sentence-transformer and OpenAI models) |
| `l2sq`   | you want squared Euclidean distance                                     |
| `negdot` | you want dot-product similarity over unnormalized vectors               |

## See also

* [Indexing](/guides/indexing)
* [Vector search](/guides/search#vector-search)
* [Quickstart](/quickstart)
