Skip to content

Add Amazon DynamoDB vector search example - #3003

Open
LeeroyHannigan wants to merge 3 commits into
openai:mainfrom
LeeroyHannigan:feat/dynamodb-vector-search
Open

Add Amazon DynamoDB vector search example#3003
LeeroyHannigan wants to merge 3 commits into
openai:mainfrom
LeeroyHannigan:feat/dynamodb-vector-search

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Aug 21, 2026

Copy link
Copy Markdown

Summary

This PR adds a new vector database example for Amazon DynamoDB under examples/vector_databases/dynamodb/. The notebook shows how to use DynamoDB vector indexes with OpenAI embeddings end to end: creating a table with a vector index, loading the shared Wikipedia embeddings dataset, running similarity searches with text-embedding-ada-002 query embeddings, using search schemas for tenant isolation and inline filtering, and feeding retrieved context to a model for a grounded answer.

The notebook runs against Amazon DynamoDB by default and includes an optional local backend via a docker-compose.yml, so readers can complete the whole walkthrough without an AWS account and move to DynamoDB by flipping one flag. All cells are executed and the committed outputs come from a real DynamoDB and OpenAI run.

Motivation

DynamoDB recently added native vector search (VectorIndexes on the table, queried with SearchVectors), and there is currently no DynamoDB example in the cookbook's vector database collection. DynamoDB is one of the most widely used operational databases, and its vector search model differs from most entries in the collection in a way that's useful to show: embeddings live in the same table as the operational data they describe, written in the same PutItem call, with no separate cluster to manage.

Two things in the notebook go beyond the standard getting-started pattern:

  • Enforced tenant isolation: HASH search schema elements make query scoping mandatory - the service rejects unscoped searches outright rather than relying on query discipline. The notebook demonstrates the rejection and the scoped results, which matters for multi-tenant and agent-memory workloads.
  • A local development path: the compose file runs ExtendDB, an open-source DynamoDB-compatible engine maintained by engineers at AWS that supports SearchVectors, so readers can run the full notebook without an AWS account.

Disclosure: I work at AWS on DynamoDB and I maintain ExtendDB. The notebook defaults to Amazon DynamoDB; the emulator is an optional convenience for readers without an AWS account.


For new content

When contributing new content, read through our contribution guidelines, and mark the following action items as completed:

  • I have added a new entry in registry.yaml (and, optionally, in authors.yaml) so that my content renders on the cookbook website.
  • I have conducted a self-review of my content based on the contribution guidelines:
    • Relevance: This content is related to building with OpenAI technologies and is useful to others.
    • Uniqueness: I have searched for related examples in the OpenAI Cookbook, and verified that my content offers new insights or unique information compared to existing documentation.
    • Spelling and Grammar: I have checked for spelling or grammatical mistakes.
    • Clarity: I have done a final read-through and verified that my submission is well-organized and easy to understand.
    • Correctness: The information I include is correct and all of my code executes successfully.
    • Completeness: I have explained everything fully, including all necessary references and citations.

Getting-started notebook covering table creation with vector indexes,
loading the shared Wikipedia embeddings dataset, SearchVectors queries
with OpenAI embeddings, mandatory tenant scoping via HASH search schema
elements, inline filters, and grounded completion from retrieved
context. All cells executed against Amazon DynamoDB and the OpenAI API.
Includes an optional docker-compose local backend.
@LeeroyHannigan
LeeroyHannigan requested a review from a team as a code owner August 21, 2026 14:19

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 793c3f6cad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"\n",
"Real applications rarely search a whole table. A `SearchSchema` on the vector index declares attributes you can constrain at query time:\n",
"\n",
"- `HASH` elements partition the index. Scoping on them becomes **mandatory**: the service rejects any search that does not pin them, so cross-tenant reads are impossible to express rather than merely discouraged.\n",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Do not present SearchSchema as tenant isolation

When a multi-tenant app lets callers influence the tenant value, this is not an isolation boundary: the AWS DynamoDB vector-search docs say a vector index partition key is for data locality/performance and that any principal with dynamodb:SearchVectors can search any partition key value. This text teaches readers that cross-tenant reads are impossible to express, so they could omit real authorization checks; describe the HASH element as mandatory query scoping and still require tenant authorization separately. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/VectorSearchWorkingWith.html

Useful? React with 👍 / 👎.

},
"outputs": [],
"source": [
"! pip install \"boto3>=1.43.64\" openai pandas numpy wget"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pin the OpenAI SDK high enough for Responses

This install line can leave an existing openai 1.x package in place, and requirements.txt also allows openai>=1.0.0, but the notebook later calls openai_client.responses.create. The v1.0.0 OpenAI Python client exposes resources like chat and embeddings but not responses, so users running under a resolver/constraint that selects the documented minimum will hit AttributeError in the final RAG cell; require a Responses-capable SDK version, such as openai>=1.66.0, everywhere the notebook documents installation. https://raw.githubusercontent.com/openai/openai-python/v1.0.0/src/openai/_client.py

Useful? React with 👍 / 👎.

| Index declaration | `VectorIndexes` on `CreateTable` or `UpdateTable` |
| Distance functions | `COSINE`, `DOT_PRODUCT`, `EUCLIDEAN` |
| Query API | `SearchVectors` with `SearchVector`, `TopK`, optional `SearchConditionExpression` |
| Scoring | `Score` is the distance: lower is more similar |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Qualify scoring for DOT_PRODUCT

Because the table lists DOT_PRODUCT as a supported distance function two rows above, this scoring summary is wrong for that option: DynamoDB reports lower scores as more similar for COSINE/EUCLIDEAN, but higher scores as more similar for DOT_PRODUCT. Readers who switch the sample index to dot product would invert result interpretation or evaluation if they follow this README; qualify the row by distance function. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/VectorSearchWorkingWith.html

Useful? React with 👍 / 👎.

…PRODUCT scoring

Search schemas are mandatory query scoping, not an authorization
boundary; callers with SearchVectors permission can search any
partition value, so the notebook and README now say to enforce tenant
access control with IAM or the application layer. The openai floor is
raised to 1.66.0 (first release with the Responses API used in the
final cell). The README scoring row is qualified per distance
function: DOT_PRODUCT reports higher as more similar.
@LeeroyHannigan

Copy link
Copy Markdown
Author

Addressed all three review findings in 4ba282f:

  • Scoping vs authorization (P1): reworded throughout. Search schemas are now described as mandatory query scoping, with an explicit note that they are not an authorization boundary and that tenant access control belongs in IAM or the application layer.
  • OpenAI SDK floor (P2): raised to openai>=1.66.0 in the install cell and requirements.txt (first release with the Responses API used in the final cell).
  • DOT_PRODUCT scoring (P2): README scoring row now qualified per distance function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant