---
title: "Record the embedding model with every · Agent Wranglers"
url: https://agentwranglers.se/playbook/search/engines-and-indexes/embedding-model-version
id: SRH-4
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 922
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Record the embedding model with every vector

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Engines and indexes](https://agentwranglers.se/playbook/search/engines-and-indexes.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: SRH-4
- Level: Recommended
- Chapter: [Engines and indexes](https://agentwranglers.se/playbook/search/engines-and-indexes.md)
- Rule: Store the embedding model name and version with every vector. Never compare vectors from two different embedding models.
- Check: A query counts vectors per embedding model in the live index. There is exactly one model, and it matches the model in the settings. A filtered search for a small tenant with at least 20 chunks returns 20 rows.
- How: Vectors from different models, or different versions of one model, live in different spaces. A search across both returns nonsense without any error. Add a column for the model to the vector table, and filter every search on the current model. A changed output size, such as the `dimensions` setting of some embedding APIs, counts as a new model. An approximate index, such as HNSW in pgvector, can apply filters after the scan and return fewer rows than asked. Turn on iterative index scans or keep one index per tenant, and test that a filtered search fills its limit. To change models, embed everything again into a new index, run the retrieval evals on it, then switch. Delete the old vectors afterwards. [Pin the model version](https://agentwranglers.se/playbook/ai-features/prompts-as-code/pin-model-versions.md) so the provider cannot change it under you.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### SQL example

```sql
SELECT embedding_model, count(*) FROM chunks GROUP BY embedding_model;
-- PASS when one row is returned and it matches the configured model
```

### TypeScript example

```ts
const hits = await db.query(
  'SELECT id, text, url FROM chunks WHERE embedding_model = $1 AND tenant_id = $2 ORDER BY embedding <=> $3 LIMIT 20',
  [config.embeddingModel, user.tenantId, toVector(await embed(question))],
);
```

### Python example

```python
hits = db.execute(
    "SELECT id, text, url FROM chunks WHERE embedding_model = %s AND tenant_id = %s ORDER BY embedding <=> %s LIMIT 20",
    (settings.embedding_model, user.tenant_id, to_vector(embed(question))),
).fetchall()
```

## Related rules

- SRH-3 [Search by meaning when the collection is small](https://agentwranglers.se/playbook/search/engines-and-indexes/small-semantic-search.md) in Search
- AIF-59 [Pin the AI model version you depend on](https://agentwranglers.se/playbook/ai-features/prompts-as-code/pin-model-versions.md) in AI features

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/search/engines-and-indexes/embedding-model-version">Agent Wranglers search playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Search by meaning when the collection is small](https://agentwranglers.se/playbook/search/engines-and-indexes/small-semantic-search.md)
- Next: [Split documents along their structure](https://agentwranglers.se/playbook/search/engines-and-indexes/structured-chunks.md)
- [Engines and indexes](https://agentwranglers.se/playbook/search/engines-and-indexes.md)
