A product owner asks for a search box where customers can type "gripping case on the coast, not too expensive". The books already live in DynamoDB, nicely modelled. Until recently, the honest answer was: we need a second database for vectors, a stream to keep it in sync, and a plan for when the two copies disagree.
That changed this year. DynamoDB can now index embeddings itself, and since November 20, 2026 the search also supports range filters, IN and OR. I built a small semantic book search for a fictional bookshop to see how it feels in practice, and wrote it up in detail in DynamoDB vector search with Lambda. Here are the parts I found most important.
How it works in a nutshell
An embedding model such as Amazon Titan Text Embeddings V2 turns text into a list of numbers. Texts with similar meaning end up close together, even without shared words. In DynamoDB you store that list as a normal attribute on the item. A vector index on the table then lets you call the new SearchVectors API with a query vector and get back the closest items, including projected attributes like title and author, so there is no second lookup.
Under the hood it is approximate nearest neighbor search: slightly less exact than comparing every vector, but fast at scale. In my example, one Lambda function creates the embedding with Bedrock when a book is stored, and a second one embeds the search text and queries the index. Infrastructure comes from the Serverless Framework.
Plan the index before you write YAML
This is the lesson I would put first: dimensions, distance function, projection, partition key and inline filters are fixed once the index exists. Changing them means creating a new index.
- Dimensions must match the model output exactly. For a book search, 512 was plenty.
-
Distance function:
COSINEis a safe default for text. Lower scores are better there, which is easy to get backwards. -
Partition key (
HASHin the search schema) splits the index, for example by genre. Every search must provide exactly one value, which keeps latency and cost down. - Inline filters such as language, year and price sit next to the vector, so DynamoDB skips non-matching items during the search instead of discarding results afterwards.
- Projection: keep it narrow. Every projected byte costs storage and search volume.
A simplified search request then looks like this:
const req = {
TableName: 'Books',
IndexName: 'BookEmbeddingIndex',
SearchVector: vector.map((v) => ({ N: String(v) })),
TopK: 5,
SearchConditionExpression:
'#genre = :genre AND #lang IN (:de, :en) AND #price <= :maxPrice',
// ExpressionAttributeNames / Values omitted for brevity
};
const res = await dynamodb.send(new SearchVectorsCommand(req));
The partition key condition always sits at the top level, joined with AND, never inside OR or NOT.
Pitfalls I would watch for
A few details are not obvious from the announcements. Vector indexes only exist on on-demand tables. The index is always eventually consistent, so a freshly written item may be missing for a moment. Fine-grained access control with conditions like dynamodb:LeadingKeys does not apply to SearchVectors, which means every function with that permission can search the whole index. If you need tenant isolation, plan separate indexes or tables. DAX does not support the new API, and an existing GSI with projection ALL will quietly copy your vectors too.
My take
For Serverless teams whose data already sits in DynamoDB, I think this is one of the most practical additions of the year. Not because it beats every vector database, but because it removes a whole sync pipeline and a second set of backups and permissions. For full-text search with facets and fine-tuned ranking, OpenSearch is still the stronger choice. And remember: a new embedding model means a new index and recomputing every vector, so put that into your operations plan early.
What the full article covers
The complete walkthrough on sascha-ms.de includes:
- The full serverless.yml with table, vector index and per-function IAM roles
- TypeScript code for embeddings, storing books and the search handler, plus tests
- An AWS CDK version using the L1 construct
- A rules table for all new filter operators and their edge cases
- Cost levers, security notes and an FAQ
๐ This is the condensed version. The full article on sascha-ms.de goes deeper โ with all code samples, diagrams and a short knowledge check.
๐ Next step: Curious what your own Lambda functions cost? Try my Lambda cost calculator โ it runs right in your browser.
๐ฌ Stay updated: New articles on serverless, AI and leading tech teams via RSS, browser push or the weekly newsletter (in German).
Originally published on sascha-ms.de. More articles on serverless, AI in everyday development and leading tech teams: sascha-ms.de/en
Top comments (0)