AWS

Recommended Vector DB Structure for Amazon Bedrock Integration

CK CK 3788 
Created at  
394 0 0

A Vector DB is a database that stores data as high-dimensional vectors, enabling efficient similarity searches based on vector embeddings generated by machine learning models. JSON-based Vector DBs offer the benefit of storing both vector embeddings and associated metadata in a single, flexible JSON document, simplifying data management, allowing for more complex filtering and querying based on metadata, and facilitating easier integration with applications that already leverage JSON for data handling.
 

JSON Document Structure

{
 "id": "doc_001",
 "content": "Your main text content here",
 "metadata": {
   "title": "Document Title",
   "source": "source_system",
   "created_at": "2025-10-01T16:57:09Z",
   "category": "documentation",
   "tags": ["api", "bedrock"]
 },
 "embedding": [0.1, -0.2, 0.3, ...],
 "chunk_index": 0,
 "parent_doc_id": "original_doc_001"
}


S3 Organization

s3://your-bucket/
├── documents/
│   ├── raw/           # Original documents
│   └── processed/     # Chunked and embedded
├── embeddings/
│   ├── by_date/2025/10/01/
│   └── by_category/api/
└── indexes/
   └── vector_index.json


Key Recommendations

Chunking Strategy:
• Keep chunks 500-1000 tokens for optimal Bedrock performance
• Include overlapping context (50-100 tokens) between chunks
• Store chunk relationships via parent_doc_id

Embedding Storage:
• Use Amazon Titan Embeddings or Cohere for consistency with Bedrock
• Store embeddings as arrays in JSON for direct querying
• Consider separate embedding files for large datasets

Metadata Design:
• Include searchable fields (title, category, tags)
• Add timestamps for freshness scoring
• Store source attribution for citations

 

Multiple files is definitely better for your use case

 

1) Performance Benefits

Single JSON Issues:

  • Must load entire file into memory for any query
  • S3 charges for full file download even for partial data
  • No parallel processing capability
  • Becomes unwieldy as data grows

 

Multiple Files Advantages:

  • Load only relevant chunks
  • Parallel S3 reads across files
  • Incremental updates without reprocessing everything
  • Better memory management

 

2) Recommended Structure

s3://your-bucket/embeddings/
├── chunk_001.json
├── chunk_002.json
├── chunk_003.json
└── index.json          # Metadata index


Individual chunk file:

{
 "id": "chunk_001",
 "content": "...",
 "embedding": [...],
 "metadata": {...}
}


Index file:

{
 "chunks": [
   {"id": "chunk_001", "file": "chunk_001.json", "category": "api"},
   {"id": "chunk_002", "file": "chunk_002.json", "category": "docs"}
 ],
 "last_updated": "2025-10-01T16:58:51Z"
}


Query Strategy

1. Read lightweight index file first
2. Filter relevant chunk files based on metadata
3. Load only matching chunk files
4. Perform vector similarity search

This approach scales much better and integrates well with your existing Bedrock API - you can add vector search as a preprocessing step before sending context to your completion endpoints.

  • Start small: Begin with ~100-500 chunks per file, adjust based on your query patterns.

 

Amazon Bedrock Code Example

import boto3

# Create a client
client = boto3.client(service_name="bedrock-runtime")

# Example prompt
prompt = """You are a helpful assistant. 
Summarize the following text in 3 bullet points:

"Amazon Bedrock makes it easy to build and scale generative AI applications
using foundation models without needing to manage infrastructure.""""

response = client.invoke_model(
    modelId="anthropic.claude-v2",  # You can choose different models
    body=json.dumps({
        "prompt": prompt,
        "max_tokens_to_sample": 300,
        "temperature": 0.7,
        "top_p": 0.9
    }),
    accept="application/json",
    contentType="application/json"
)

# Parse response
output = json.loads(response['body'].read())
print(output["completion"])

 

Amazon Bedrock with FAISS

import boto3
import faiss
import numpy as np
import json

# 1. Initialize Bedrock client
client = boto3.client("bedrock-runtime")

# 2. Create documents (knowledge base)
documents = [
    "Amazon Bedrock lets you build generative AI apps with foundation models.",
    "FAISS is a library for efficient similarity search and clustering of dense vectors.",
    "Retrieval-Augmented Generation (RAG) improves LLMs by grounding answers in external knowledge."
]

# 3. Create embeddings with Amazon Titan Embeddings
def get_embedding(text):
    response = client.invoke_model(
        modelId="amazon.titan-embed-text-v1",
        body=json.dumps({"inputText": text}),
        contentType="application/json",
        accept="application/json"
    )
    output = json.loads(response["body"].read())
    return np.array(output["embedding"])

embeddings = [get_embedding(doc) for doc in documents]

# 4. Build FAISS index
dim = len(embeddings[0])
index = faiss.IndexFlatL2(dim)
index.add(np.array(embeddings).astype("float32"))

# 5. Query workflow
query = "How can I combine FAISS with Bedrock?"
query_vector = get_embedding(query).astype("float32").reshape(1, -1)

# Find top-k relevant documents
k = 2
distances, indices = index.search(query_vector, k)

retrieved_docs = [documents[i] for i in indices[0]]
context = "\n".join(retrieved_docs)

# 6. Send to Claude for response
prompt = f"""You are an AI assistant.
Answer the question using the context below.

Context:
{context}

Question:
{query}
"""

response = client.invoke_model(
    modelId="anthropic.claude-v2",
    body=json.dumps({
        "prompt": prompt,
        "max_tokens_to_sample": 300,
        "temperature": 0.7
    }),
    contentType="application/json",
    accept="application/json"
)

output = json.loads(response["body"].read())
print("AI Response:\n", output["completion"])

 

Tags Amazon Bedrock Bedrock FAISS JSON Vector DB Vector DB Structure Vector Database Facebook X
Comments 0
Similar posts
  1. Milvus & FAISS: Decoding Their ML Synergy
    286
  2. Getting Started with FAISS: A CentOS 7 Installation Guide
    288
  3. Image Embeddings for Vector Databases
    257
  4. Vector Databases: From Embeddings to Application
    323
  5. Understanding Elasticsearch from Installation to Trouble Shooting
    915
  6. Save clustering result (aka dictionary) in JSON and Reuse loaded result
    382
  7. Understanding Amazon Bedrock Agent for AI-based ChatBot
    647
  8. Technical Hierarchy of AI Agents
    826
  9. Dynamic JSON Editor based in HTML/JavaScript
    514
  10. When you need AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for Amazon Bedrock
    545
  11. Milvus and LLM Integration - Very Smart Approach!
    305
  12. Integrating VectorDB stored in S3 with Amazon Bedrock
    429
  13. How to overcome the prompt size limit when you use Claude via Bedrock - Chunking / Splitting the Input
    502
  14. When you face 504 Gateway Timeout while you wait a response from Bedrock in Fast API
    540
  15. Default Timeout for Amazon Bedrock invoke_model
    742
  16. Architecting ML/LLM Ad Targeting with Kafka, Flink, FAISS, and Milvus
    285
  17. The Core of Vector Databases: Embeddings and LLM Dependency
    267
  18. Your Blueprint for an LLM & Vector DB Insurance Product Q&A
    267
  19. Demystifying FAISS: Your Guide to ANN(Approximate Nearest Neighbor) Search
    327
  20. AWS Multi-Agent Collaboration Approach: Fully Managed vs. Code-based Implementation
    292
  21. Vector Database Integration on Fully Managed Multi-Agent Environment
    319
  22. Embeddings on the Lakehouse: What Snowflake and Databricks Actually Do (and Don't)
    303
  23. Designing a Data Curation System Around a Vector Database
    230
  24. What is RedisVL?
    117
  25. JSON format control in PHP
    697
  1. How Netflix Runs Recommendations for Hundreds of Millions of Users Using Amazon SageMaker & Metaflow
    183
  2. Why Amazon VPC satisfies with PCI-DSS and SOC 2 Type on Fintech Industry?
    649
  3. You shouldn't use Amazon CloudFront distribution as an origin
    643
  4. Amagi CLOUDPORT Architecture based on AWS for FAST for channel playout on AWS
    1,330
  5. Creating a serverless Apache Kafka publisher using AWS Lambda
    568
  6. AWS System Design Example - Instagram Architecture
    1,928
  7. A Python script to create an EC2 Spot instance using boto3
    1,611
  8. A Python/PHP code to deregister anormalous instaces in Amazon ECS
    1,861
  9. Where to get AWS API Key at AWS Management Console?
    1,078
  10. Media sharing service architecture in AWS
    10,375
  11. Enterprise Data Lake Architecture based on AWS
    10,412
  12. "502 Bad Gateway" Error easy to happen at the combination of nginx and node.js in AWS Elastic Beanstalk
    10,495
  13. How to Set Up and Deploy Containerized Applications with AWS ECS
    10,683
  14. Power of Containerized Deployment with AWS ECS
    10,599
  15. FAISS Already Does ANN... So Why Do Top Teams Still Pay for SageMaker?
    315
  16. Product Marketing & Recommendation Architecture in AWS for e-commerce website
    10,748
  17. What cause a 502 bad gateway error in AWS environment?
    445
  18. Building an AWS SAM(Serverless Application Model) Project
    901
  19. Teraform from the scratch
    1,362
  20. Check incomplete multipart uploads if AWS S3 storage size is abnormally big huge compared to the origin storage
    11,599
  21. Importing a wild card domain SSL certificate into AWS Certificate Manager
    10,351
  22. AWS Lambda Example based on Teraform
    904
  23. Simple AWS ECS example based on Teraform
    995
  24. Web front-end architecture in AWS for e-commerce website
    371
  25. Web Application Hosting provides the reliable, scalable, secure, and high-performance infrastructure
    10,622
  26. Time series processing architecture in AWS
    10,563
  27. Synchronous online gaming architecutre in AWS - Highly Available, Scalable & Elastic to support Millions of Players
    10,425
  28. Secure and Scalable LAMP Service Architecture in AWS
    10,667
  29. Live streaming / Static Content & Media Service based on AWS
    10,664
  30. Large scale messenger service architecture in AWS - Slack case study
    11,675
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    31
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    57
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    51
  4. How do I create animated background for Google Meet?
    23,256
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    273
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    105
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    170
  8. Array of arguments passed to script in PHP
    99
  9. Invalid Auction Storms in Ad Tech
    108
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    209
  11. The Two Clocks of Ad Server Architecture
    78
  12. Frequency Cap Architecture Overview
    527
  13. Collecting Proof-of-Play from 100,000 Screens
    154
  14. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    303
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    247
  16. TPU & GPU Cluster Management Tools
    258
  17. The Concept of Scaffolding in AI Agents
    245
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    599
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    269
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    355
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    207
  22. Machine Learning: Training vs. Ranking
    231
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    229
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    204
  25. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  26. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    674
  27. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    201
  28. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    233
  29. Understanding Data Lineage
    272
  30. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    176