Urgent.News

What's breaking now, across thousands of outlets.

Editions

Tech

Adding Semantic Search to an Existing DynamoDB Table with Vector Indexes

Whenever someone asks me to add search to an application, I try to find ways around it. The implementation itself isn't the problem, it's everything that comes with it: extra components to manage, more failure points, and the constant challenge of keeping data in sync. For the past few years, I've worked a lot with DynamoDB and with the introduction of Vector Search I feel a lot more comfortable…

When asked to add search functionality to an application, the complexity and overhead involved can be significant. Maintaining extra components, managing potential failure points, and ensuring data consistency can be a challenge. For the past few years, the author has been working with DynamoDB, and with the introduction of Vector Search, they feel more comfortable incorporating this type of functionality.

AWS has recently released another vector store, and this post aims to demonstrate how to add vector search to an existing DynamoDB table. The current API utilizes a serverless setup, including SAM for infrastructure, API Gateway in front, Lambda functions behind, and DynamoDB for storage. The API currently provides basic CRUD operations to manage recipes, such as create, read, update, delete, and list.

Adding filters to query specific data becomes complex when using DynamoDB, as it requires creating Global Secondary Indexes (GSI) for each permutation, which is not scalable. Traditionally, a separate data pipeline was necessary to index the data and provide search functionality. However, with the advent of vector search in DynamoDB, vector embeddings can be stored alongside the data, enabling direct search.

This allows users to search recipes using natural language queries based on the meaning, rather than just exact keyword matches.

Semantic search works by converting text into embeddings, which are lists of numbers representing the meaning of the text. Texts with similar meanings end up close together in the vector space, allowing for searching by intent instead of keywords. To add vector embeddings, the Amazon Bedrock's Titan Text Embeddings V2 model is used, which produces 1024-dimension vectors normalized using cosine similarity.

The text to be embedded includes the recipe's name, description, cuisine, dietary tags, ingredients, preparation time, and cooking time.

A function is created to build the embedding text by combining the recipe's key fields into a single string. The embedding is then generated inline, making every item searchable as soon as it's written. DynamoDB vector indexes enable this functionality without the need for a separate service. The embedding is stored as an attribute on the item, and a vector index is created over that attribute. Queries can be made using a dedicated similarity API.

The vector index is not supported by CloudFormation, so a script is added to run after deployment to create the index using the UpdateTable command if it doesn't already exist. The index is configured with cosine distance, 1024 dimensions to match the Titan output, and an inline filter on cuisine. This allows for prefiltering results, similar to a regular DynamoDB index's partition key but without being required.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

My Wi-Fi networks

I have configured my Wi-Fi router to provide four wireless networks: HomeNet_Main HomeNet_Guest HomeNet_SmartDevices HomeNet_HVAC HomeNet_Main This is the primary wireless network for our home.

  • Four Wi-Fi networks configured on router with distinct purposes
  • HomeNetMain for personal devices, hidden SSID, WPA2/WPA3 encryption
  • HomeNetSmartDevices for IoT devices, isolated security measures

Two YubiKeys, One Prompt Too Many

I carry two YubiKeys. One lives on my keyring, one lives in a drawer, and both are enrolled everywhere that matters. A hardware token with no backup is a single point of failure you have chosen on…

  • Two YubiKeys used for GitHub authentication
  • PIN prompts triggered by resident key generation
  • Custom configurations bypass authentication dialog

More from Thursday 20 August →