---
title: "Efficient Data Retrieval from Images: Using LlamaIndex, Mongo, and AWS"
description: "This blog explains how image-centric RAG improves search accuracy by indexing image embeddings directly instead of relying on captions. Using CLIP or VoyageAI models, MongoDB Atlas Vector Search, and LlamaIndex, it creates a low-cost, scalable pipeline where text or image queries can instantly…"
url: https://lidvizion.ai/blog/efficient-data-retrieval-from-images-using-llamaindex-mongo-and-aws/
site: Lid Vizion
index: https://lidvizion.ai/llms.txt
---

[Insights](https://lidvizion.ai/blogs/) Architecture & Orchestration 12 min read 2026-02-16

# Efficient Data Retrieval from Images: Using LlamaIndex, Mongo, and AWS

This blog explains how image-centric RAG improves search accuracy by indexing image embeddings directly instead of relying on captions. Using CLIP or VoyageAI models, MongoDB Atlas Vector Search, and LlamaIndex, it creates a low-cost, scalable pipeline where text or image queries can instantly…

By [Shawn Wilborne](https://lidvizion.ai/author/shawn-wilborne/) [Architecture & Orchestration](https://lidvizion.ai/blog-categories/architecture-orchestration/)

Tags: [Video Processing](https://lidvizion.ai/tags/video-processing/), [MongoDB Atlas Vector Search](https://lidvizion.ai/tags/mongodb-atlas-vector-search/), [Image Retrieval Augmented Generation](https://lidvizion.ai/tags/image-retrieval-augmented-generation/), [AWS Lambda](https://lidvizion.ai/tags/aws-lambda/)

![Efficient Data Retrieval from Images: Using LlamaIndex, Mongo, and AWS](https://rcicvvtcawdbfiuzwexb.supabase.co/storage/v1/object/public/webflow-media/webflow/media/cms/68ceb19e6961feb9ad4ec355/efficient-data-retrieval-from-images-using-llamaindex-mongo-and-aws.png)

**Image-centric RAG** augments (or replaces) text-only retrieval by indexing **image embeddings** directly. Instead of captioning images first (and losing detail), we embed images (e.g., **CLIP**) and run **vector similarity search** to fetch the most relevant visuals for a text or image query. LlamaIndex’s **MultiModalVectorStoreIndex** can store CLIP/VoyageAI embeddings in **MongoDB Atlas**, so a plain text query retrieves semantically similar **images** (and/or their captions) from one vector store—often more accurate than caption-only pipelines ([OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search); [LlamaIndex → Mongo](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/)).

**Atlas Vector Search** is built-in (no extra fee for the feature), and even the **Free Tier** supports vector indexing—making image RAG cost-friendly for startups ([Mongo forum](https://www.mongodb.com/community/forums/t/is-vector-search-feature-paid-or-free/267191); [Mongo pricing](https://www.mongodb.com/pricing)).

## Architecture at a glance

**S3 (images) → Lambda (embeddings/captions) → MongoDB Atlas (vectors + metadata) → LlamaIndex (retriever) → LLM/UI**

- **Storage:** Amazon S3 holds raw images (≈$0.023/GB-mo for Standard) and triggers processing on upload ([S3 pricing guide](https://www.cloudzero.com/blog/s3-pricing/)).
- **Compute:** An embedding service (Lambda, SageMaker, or a small GPU container) generates vectors (CLIP, VoyageAI) and optional captions (BLIP → then text-embeddings). Lambda pricing is **$0.20/million requests** + **$0.00001667/GB-s** ([AWS Lambda pricing](https://aws.amazon.com/lambda/pricing/)).
- **Index:** MongoDB Atlas with a **Vector Search** index on `embedding`. LlamaIndex’s `MongoDBAtlasVectorSearch` adapter wires it up ([LlamaIndex Mongo](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/)).
- **Query:** A user’s **text** or **image** query is embedded in the same space; LlamaIndex retrieves **Top-K** vectors (with optional metadata filters) and returns images + captions to the app/LLM ([LlamaIndex multimodal example](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/); [OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search)).

## Choosing embedding models (CLIP, VoyageAI, BLIP)

- **Direct image embeddings:** CLIP (e.g., ViT-B/32 via PyTorch) or **VoyageAI multimodal** map images and text into a **shared** vector space—perfect for text→image and image→image search ([OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search); [LlamaIndex multimodal example](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/)).
- **Caption-then-embed:** If you need captions, run **BLIP/BLIP-2** to generate one, then embed with a text model (e.g., OpenAI text-embedding). This is flexible, but tends to be **lossier** than CLIP-style direct image embeddings for nearest-neighbor retrieval ([OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search)).

**Implementation tip:** Keep **one canonical dimension** (e.g., 512 or 768) across the corpus; don’t mix vector sizes in the same index.

## Ingestion pipeline (step-by-step)

1. **Upload to S3 (with metadata)** Store the image and record metadata (filename, tags, EXIF/GPS). S3 events will kick off embedding. Costs are tiny: **100 GB ≈ $2.30/mo**, **1 TB ≈ $23/mo** ([S3 pricing guide](https://www.cloudzero.com/blog/s3-pricing/)).
2. **Embedding extraction (Lambda or endpoint)**
  - S3 event → Lambda pulls the image, calls CLIP/VoyageAI (local PyTorch, SageMaker endpoint, or Bedrock-hosted).
  - Optional: run **BLIP** to create a caption and a **text embedding** for hybrid search. **Cost sanity check:** 3 M images @ **120 ms** each, **1.5 GB** memory → ~**540k GB-s**. With **400k GB-s free** + **1M free requests**, net ≈ **$2.33** (compute) + **$0.40** (2M billable requests) ≈ **$2.73** total ([AWS Lambda pricing](https://aws.amazon.com/lambda/pricing/)).
3. **Index in MongoDB Atlas (vectors + metadata)** Configure **Vector Search** on `embedding` (cosine or dot-product). Then store documents like:
4. `{` `"_id": "img_123",` `"s3_key": "catalog/2025/08/23/img_123.jpg",` `"embedding": [/* d floats */],` `"caption": "vintage red coupe on city street",` `"meta": {"brand":"Acme", "category":"car", "uploadedAt":"2025-08-23T15:12:00Z"}` `}`
5. Vector Search is **included**; you pay for the cluster (e.g., Shared/Free, or **M20 ≈ $0.08/hr** ≈ $60/mo) ([Mongo pricing](https://www.mongodb.com/pricing); [forum](https://www.mongodb.com/community/forums/t/is-vector-search-feature-paid-or-free/267191)).
6. **Build the LlamaIndex** Use `MongoDBAtlasVectorSearch` in the `StorageContext`, then build a `MultiModalVectorStoreIndex` from your image docs ([LlamaIndex Mongo](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/); [multimodal example](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/)).

## Minimal setup (illustrative)

**Create Atlas vector index & build LlamaIndex**

`# pip install llama-index llama-index-vector-stores-mongodb` `from llama_index.core import StorageContext, VectorStoreIndex, Document` `from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch` `from pymongo import MongoClient` `MONGO_URI = "MONGODB_URI (redacted)"` `client = MongoClient(MONGO_URI)` `db = client["image_search"]` `coll = db["images"]` `# 1) Configure Atlas Vector Search (one-time, in Atlas UI or via code)` `# Example (conceptual): dimensions=512, cosine similarity` `# vector_store.create_vector_search_index(path="embedding", dimensions=512, similarity="cosine")` `# 2) Wire Mongo vector store into LlamaIndex` `vector_store = MongoDBAtlasVectorSearch.from_collection(coll, index_name="embedding_index")` `storage_ctx = StorageContext.from_defaults(vector_store=vector_store)` `# 3) Upsert documents with embeddings already present in Mongo (from your Lambda step)` `# Or, if you embed here, attach your image embed model to VectorStoreIndex.from_documents(...)` `index = VectorStoreIndex.from_documents([], storage_context=storage_ctx)` `# 4) Query (text -> image)` `retriever = index.as_retriever(similarity_top_k=6)` `results = retriever.retrieve("red vintage cars at night")` `for node in results:` `print(node.metadata.get("s3_key"), node.score)`

_(Exact helpers vary by version; align with the current LlamaIndex API and your Atlas index settings.)_ Docs: LlamaIndex Mongo adapter/API ([link](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/)); multimodal example ([link](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/)).

## Hybrid retrieval: vector + filters

Blend **semantic** and **structured** search in one call:

- **Vector**: nearest neighbors in `embedding`.
- **Filters**: Mongo fields—e.g., `{ "meta.category": "car", "meta.uploadedAt": { "$gte": ... } }`.
- **LlamaIndex** supports metadata filters + Top-K vector retrieval, e.g., “red sneakers” **AND** `brand=Acme`.

This yields precise results without over-fetching and keeps your index compact.

## Serving results

- Keep originals in **S3**; front with **CloudFront** for global, low-latency delivery.
- Return **signed URLs** to clients, or pipe results into an **LLM** for multimodal chat (“show and describe the top-3 images”).
- For “find similar to this image,” embed the query image client-side and hit the same vector store.

## Cost & sizing cheat-sheet

- **Atlas Vector Search:** feature is free; pay for cluster (Free/Shared → $, **M20 ≈ $60/mo**). Plenty for 10^5–10^6 images if vectors are small ([forum](https://www.mongodb.com/community/forums/t/is-vector-search-feature-paid-or-free/267191); [pricing](https://www.mongodb.com/pricing)).
- **S3:** **$0.023/GB-mo** (Standard). 50 GB ≈ **$1.15/mo**; 1 TB ≈ **$23/mo** ([S3 guide](https://www.cloudzero.com/blog/s3-pricing/)).
- **Lambda embedding jobs:** essentially dollars-scale for **millions** of images, thanks to free-tiers + per-use pricing ([Lambda pricing](https://aws.amazon.com/lambda/pricing/)).
- **Throughput:** Use **S3 events** + **Lambda concurrency** for bursts; fall back to **SageMaker** or a small GPU service for heavy models/batching.

## Best practices

- **Canonicalize embeddings:** uniform dims & metric (cosine vs dot).
- **Normalize vectors:** improves search stability.
- **Store captions + EXIF:** hybrid queries (“red coats” + `city=Paris`).
- **Chunk big batches:** throttle to respect Atlas write limits; use bulk writes.
- **Version your models:** keep `embedding_v` in docs; reindex selectively on upgrades.
- **Test metrics:** A/B CLIP vs BLIP-caption+text-embed on your data; CLIP often wins for pure image similarity ([OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search)).

## TL;DR

- **Image-first RAG** with **CLIP/VoyageAI** embeddings in **MongoDB Atlas Vector Search** improves accuracy over caption-only pipelines ([OpenAI Cookbook](https://cookbook.openai.com/examples/custom_image_embedding_search)).
- **AWS + LlamaIndex** gives a tiny, pay-as-you-go stack: **S3 → Lambda → Atlas**; LlamaIndex handles multimodal retrieval & filters ([LlamaIndex Mongo](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/); [multimodal example](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/)).
- **Costs stay low:** Atlas small cluster (~$60/mo), S3 pennies/GB, Lambda dollars for **millions** of embeddings ([Mongo pricing](https://www.mongodb.com/pricing); [S3](https://www.cloudzero.com/blog/s3-pricing); [Lambda](https://aws.amazon.com/lambda/pricing/)).
- **Result:** fast, accurate **visual search** + hybrid filters that make your images as searchable and actionable as text.

## URL Index

1. Multimodal RAG with CLIP (image search) — OpenAI Cookbook [https://cookbook.openai.com/examples/custom_image_embedding_search](https://cookbook.openai.com/examples/custom_image_embedding_search)
2. Atlas Vector Search paid or free? — MongoDB Forum [https://www.mongodb.com/community/forums/t/is-vector-search-feature-paid-or-free/267191](https://www.mongodb.com/community/forums/t/is-vector-search-feature-paid-or-free/267191)
3. LlamaIndex → MongoDB Atlas Vector Search (API) [https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/](https://docs.llamaindex.ai/en/stable/api_reference/storage/vector_store/mongodb/)
4. MongoDB Pricing (Shared/Dedicated incl. M20) [https://www.mongodb.com/pricing](https://www.mongodb.com/pricing)
5. S3 Pricing (guide/estimates) [https://www.cloudzero.com/blog/s3-pricing/](https://www.cloudzero.com/blog/s3-pricing/)
6. AWS Lambda Pricing (GB-s & free-tier) [https://aws.amazon.com/lambda/pricing/](https://aws.amazon.com/lambda/pricing/)
7. (same) [https://aws.amazon.com/lambda/pricing/](https://aws.amazon.com/lambda/pricing/)
8. LlamaIndex multimodal (VoyageAI + Mongo) example [https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/](https://docs.llamaindex.ai/en/stable/examples/multi_modal/llamaindex_mongodb_voyageai_multimodal/)

[PreviousBuilding a Secure Expungement Automation Tool with Lid Vizion: OCR, Rules, Form Fill, and Secure Storage](https://lidvizion.ai/blog/secure-expungement-automation-ocr-rules-pdf-sharepoint/) · [NextBasketball Performance AI: Lightweight Video Analytics (with the Right Resources)](https://lidvizion.ai/blog/basketball-performance-ai-lightweight-video-analytics-with-the-right-resources/)

Keep reading

## Related insights.

- [Basketball Performance AI: Lightweight Video Analytics (with the Right Resources)](https://lidvizion.ai/blog/basketball-performance-ai-lightweight-video-analytics-with-the-right-resources/): A B2B playbook for basketball clubs, academies, leagues, and apps: build player/ball tracking, event tagging, and coach-ready insights with lightweight CV—plus a curated resource stack you can trust.
- [Why Pose Estimation Is the Next Fitness Feature Moat (B2B Guide + Resources)](https://lidvizion.ai/blog/why-pose-estimation-is-the-next-fitness-feature-moat-b2b-guide-resources/): A resource-backed B2B playbook for fitness app owners, gyms, and training businesses: ship MediaPipe Pose form feedback (rep counting, scoring, coach reports) with privacy-first, edge-friendly deployment—without building a full ML team.

## Where does your workflow get stuck?

[Discuss the workflow](https://lidvizion.ai/contact/) · [Book a call](https://calendar.app.google/bB26LdA9e2gmGFp69)
