Skip to content

About

Vector database project using CLIP image/text embeddings with Pinecone and MongoDB Atlas for image similarity search, KNN classification, and cross-modal text-to-image retrieval.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Β 
Β 

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


 /$$    /$$                      /$$                         /$$    /$$ /$$                        
| $$   | $$                     | $$                        | $$   | $$|__/                        
| $$   | $$ /$$$$$$   /$$$$$$$ /$$$$$$    /$$$$$$   /$$$$$$ | $$   | $$ /$$  /$$$$$$  /$$  /$$  /$$
|  $$ / $$//$$__  $$ /$$_____/|_  $$_/   /$$__  $$ /$$__  $$|  $$ / $$/| $$ /$$__  $$| $$ | $$ | $$
 \  $$ $$/| $$$$$$$$| $$        | $$    | $$  \ $$| $$  \__/ \  $$ $$/ | $$| $$$$$$$$| $$ | $$ | $$
  \  $$$/ | $$_____/| $$        | $$ /$$| $$  | $$| $$        \  $$$/  | $$| $$_____/| $$ | $$ | $$
   \  $/  |  $$$$$$$|  $$$$$$$  |  $$$$/|  $$$$$$/| $$         \  $/   | $$|  $$$$$$$|  $$$$$/$$$$/
    \_/    \_______/ \_______/   \___/   \______/ |__/          \_/    |__/ \_______/ \_____/\___/ 
                                                                                                   

View the world through vectors.


Python CLIP Pinecone MongoDB License Status


Multi-modal vector search engine β€” image similarity, zero-shot KNN classification, and text-to-image retrieval powered by CLIP embeddings.



✦ What is VectorView?

VectorView is a multi-modal vector search system that converts raw images and natural language into high-dimensional embeddings using OpenAI's CLIP model β€” then stores, indexes, and retrieves them via Pinecone and MongoDB Atlas Vector Search.

No supervised training. No labeled pipelines. Just embeddings and geometry.

You give it: "A Running Dog"
It returns: πŸΆπŸ•β€” the closest matching images in the dataset


✦ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       VectorView Pipeline                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                 β”‚
β”‚   πŸ“ Animal Dataset (cats / dogs / wolves)                      β”‚
β”‚        β”‚                                                        β”‚
β”‚        β–Ό                                                        β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    CLIP Model (ViT-B/32)                      β”‚
β”‚   β”‚   Image     β”‚ ──────────────────────────► [512-d vector]    β”‚
β”‚   β”‚   Encoder   β”‚                                    β”‚          β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                    β”‚          β”‚
β”‚                                                      β–Ό          β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚   β”‚   Text      β”‚ ──► [512-d vector] ────►│  Vector Database β”‚  β”‚
β”‚   β”‚   Encoder   β”‚                         β”‚                  β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                         β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚                                           β”‚  β”‚  Pinecone  β”‚  β”‚  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚   β”‚           Query                  β”‚    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚  β”‚
β”‚   β”‚  "cute Kitty" / query_image.jpg  β”‚    β”‚  β”‚  MongoDB   β”‚  β”‚  β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚  β”‚
β”‚             β”‚                             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚             β–Ό                                      β”‚            β”‚
β”‚        Cosine Similarity  ◄────────── Top-K Results (k=5)       β”‚
β”‚                                                                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜


✦ Tasks

πŸ” Task 1 β€” Image Similarity Search
**Goal:** Given a query image, retrieve the most visually similar images from the dataset.

How it works:

  1. Embed the query image with CLIP into a 512-d vector
  2. Send the vector to Pinecone
  3. Pinecone computes cosine similarity and returns the top-K nearest neighbors
  4. Display the results alongside similarity scores

Output: Screenshot 2026-06-17 150443 image

🏷️ Task 2 β€” Zero-Shot KNN Classification
**Goal:** Classify an unknown image without ever training a classifier.

How it works:

  1. Embed the query image with CLIP
  2. Retrieve the top-K nearest neighbors from Pinecone
  3. Run a majority vote on neighbor labels
  4. The predicted class is the most common label among neighbors β€” zero training required

Output: image image

πŸ’¬ Task 3 β€” Cross-Modal Search (Text β†’ Image)
**Goal:** Search the image dataset using natural language queries.

How it works:

  1. Encode a text prompt (e.g. "wolf in snow") with CLIP's text encoder
  2. The text vector lands in the same embedding space as the images
  3. MongoDB Atlas $vectorSearch finds the nearest image vectors
  4. Return and display the top matching images

Output: image image image image image image


✦ Tech Stack

Component Tool Role
Embedding Model openai/clip-vit-base-patch32 Image + Text β†’ 512-d Vector
Vector DB (Primary) Pinecone (Serverless) Hosted ANN search, Tasks 1 & 2
Vector DB (Comparison) MongoDB Atlas Vector search via $vectorSearch, Task 3
Runtime Python 3.10+, Google Colab Development environment
Visualization Matplotlib Display query + result images


✦ Setup

1. Clone the repo

git clone https://github.com/your-username/vector-view.git
cd vector-view

2. Install dependencies

pip install torch torchvision transformers pinecone pymongo[srv] Pillow matplotlib tqdm

3. Prepare the dataset

Organize your images like this:

vector-view/
└── animal_dataset/
    β”œβ”€β”€ cats/
    β”‚   β”œβ”€β”€ cat_001.jpg
    β”‚   └── ...
    β”œβ”€β”€ dogs/
    β”‚   β”œβ”€β”€ dog_001.jpg
    β”‚   └── ...
    └── wolves/
        β”œβ”€β”€ wolf_001.jpg
        └── ...

In Colab: upload animal_dataset.zip via Files β†’ Upload, then run the extraction cell.

4. Configure API credentials

Open the Configuration cell in the notebook and fill in your keys:

PINECONE_API_KEY  = "your_pinecone_key"      # app.pinecone.io
PINECONE_ENV      = "us-east-1"              # your Pinecone region
PINECONE_INDEX    = "animal-embeddings"      # auto-created
 
MONGO_URI         = "mongodb+srv://..."      # MongoDB Atlas URI
MONGO_DB          = "your_database"
MONGO_COLLECTION  = "animal_images"

5. Run the notebook

Execute cells top-to-bottom in Colab or Jupyter. Each task is self-contained after setup.



✦ Key Concepts

Why CLIP? CLIP (Contrastive Language–Image Pretraining) was trained to align image and text representations in a shared vector space. This means encode("a dog") and encode(dog_image.jpg) produce geometrically close vectors β€” enabling cross-modal retrieval with zero task-specific training.

Why Vector Databases? Traditional SQL WHERE clauses can't find similar things. Vector DBs use Approximate Nearest Neighbor (ANN) algorithms β€” like HNSW or IVFFlat β€” to find the closest vectors in milliseconds, even across millions of entries.

Cosine Similarity:

similarity(A, B) = (A Β· B) / (β€–Aβ€– Γ— β€–Bβ€–)

Range [-1, 1] β†’ closer to 1 = more similar.



✦ Pinecone vs. MongoDB Atlas

Feature Pinecone MongoDB Atlas
Type Purpose-built vector DB Multi-model DB + vector search
Setup Fully managed, API-first Atlas cluster + index config
Query Speed Extremely fast (dedicated ANN) Fast, but secondary to document ops
Metadata Filtering βœ… Native βœ… via $match pipeline
Best For Pure vector workloads Apps needing vectors + documents


✦ Observations

  • CLIP embeddings are surprisingly robust β€” text queries like "running dog" retrieve contextually correct images with no fine-tuning
  • KNN classification via vector search matches simple CNN accuracy on clean datasets with zero training overhead
  • Pinecone offers faster cold-start indexing; MongoDB is preferable when your app already stores structured documents
  • Cross-modal search degrades on ambiguous text β€” "animal" returns scattered results across all classes


✦ Project Structure

VectorView/
β”œβ”€β”€ VectorView.ipynb            # Main notebook
β”œβ”€β”€ animal_dataset/             # Image dataset (not tracked in git)
β”œβ”€β”€ screenshots/                # Output screenshots for README
└── README.md


A View From Vectors

GitHub

About

Vector database project using CLIP image/text embeddings with Pinecone and MongoDB Atlas for image similarity search, KNN classification, and cross-modal text-to-image retrieval.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages