0% found this document useful (0 votes)
2 views22 pages

? Vector Databases With Pinecone - Course Notes

The course on vector databases with Pinecone focuses on understanding core concepts, practical applications, and building a semantic search system using Python. Vector databases excel in handling high-dimensional data for tasks like similarity search, making them ideal for AI-driven applications. The course includes hands-on practice with Pinecone, a leading vector database platform, and covers various types of vector databases and their strengths and weaknesses.

Uploaded by

maryamrauf1894
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views22 pages

? Vector Databases With Pinecone - Course Notes

The course on vector databases with Pinecone focuses on understanding core concepts, practical applications, and building a semantic search system using Python. Vector databases excel in handling high-dimensional data for tasks like similarity search, making them ideal for AI-driven applications. The course includes hands-on practice with Pinecone, a leading vector database platform, and covers various types of vector databases and their strengths and weaknesses.

Uploaded by

maryamrauf1894
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

📘 Vector Databases with Pinecone — Course Notes

1️⃣ Course Overview


●​ Course Focus: Understanding vector databases — theory + hands-on practice
●​ Instructor: Ellie (Data Content Lead at 365, background in bioinformatics & ML)
●​ What you’ll learn:
○​ Core concepts of vector databases
○​ Vector spaces & similarity search
○​ Practical work using Python + Pinecone
○​ Building a semantic search system (case study)

2️⃣ What Are Vector Databases?


●​ A vector database stores and searches high-dimensional numerical vectors
●​ These vectors represent complex data like:
○​ Text
○​ Images
○​ Audio
○​ Video
●​ Vectors are usually generated by machine learning models
●​ Main strength: similarity search (finding “most similar” items, not exact matches)

3️⃣ Why Vector Databases Matter


Traditional databases struggle with:

●​ Meaning-based search
●​ High-dimensional data
●​ AI-driven applications

Vector databases excel at:

●​ Semantic search
●​ Recommendation systems
●​ Anomaly & fraud detection
●​ AI-powered personalization
4️⃣ Types of Databases Compared
🔹 SQL (Relational Databases)
●​ Data stored in tables (rows & columns)
●​ Fixed schema (strict structure)
●​ Uses SQL language
●​ Strong at:
○​ Transactions
○​ Data accuracy
○​ Complex queries
●​ Limitations:
○​ Rigid schema
○​ Scaling can be difficult

Best for: Banking, finance, structured records

🔹 NoSQL Databases
●​ Schema-less (flexible structure)
●​ Supports:
○​ Document stores
○​ Key-value stores
○​ Graph databases
○​ Wide-column stores
●​ Designed for:
○​ Large-scale data
○​ Rapid changes
○​ Horizontal scaling

Best for: Social media, streaming platforms, real-time apps

🔹 Vector Databases
●​ Store numerical vectors in high-dimensional space
●​ Optimized for:
○​ Similarity search
○​ Nearest-neighbor queries
●​ Essential for:
○​ AI & ML systems
○​ Semantic understanding
○​ Recommendation engines

Best for: AI-driven search, personalization, intelligent systems


5️⃣ Understanding Vectors (Core Concept)
●​ A vector = numerical representation of data
●​ Each dimension = a feature of the data

Examples:

●​ Music app: tempo, rhythm, mood, instruments


●​ Image app: colors, shapes, textures
●​ Text: meaning, context, semantics
●​ Distance between vectors = similarity
○​ Closer vectors → more similar content

6️⃣ Semantic Search Explained


●​ Goes beyond keyword matching
●​ Focuses on meaning
●​ Example:
○​ Searching “happy energetic songs”
○​ Results based on audio features, not just tags

Why vector DBs are ideal:​


They understand similarity mathematically through vector distance.

7️⃣ Real-World Applications


🔍 Semantic search (text, images, audio)
🎧 Music & video recommendations
●​

🏥 Medical image & case similarity


●​

🤖 Customer support automation


●​

🛡️ Fraud & anomaly detection


●​
●​

8️⃣ History & Growth of Vector Databases


●​ Early research: 2000s
●​ First commercial solution: Vectorwise (2010)
●​ Rapid growth due to:
○​ Explosion of unstructured data
○​ AI & ML adoption
○​ Limits of SQL/NoSQL for similarity search
●​ Pinecone: built to solve large-scale similarity search challenges

9️⃣ Pinecone in This Course


●​ A leading vector database platform
●​ You’ll learn to:
○​ Create & delete indexes
○​ Manage vectors using Python
○​ Build a semantic search engine
●​ Tools used:
○​ Python
○​ Jupyter Notebook
○​ Pinecone API

🔑 Key Takeaways
●​ Vector databases are AI-native databases
●​ They enable meaning-based understanding
●​ SQL = structured precision
●​ NoSQL = flexible scale
●​ Vector DBs = intelligent similarity
●​ Critical for modern AI products

📘 Vector Databases with Pinecone —


Notes (Part 2)

1️⃣ Types of Vector Databases (Overview)


●​ No single vector database is perfect
●​ Each solution has trade-offs:
○​ Ease of use vs customization
○​ Managed vs self-hosted
○​ Performance vs complexity
●​ The ecosystem is evolving fast → new tools & updates constantly

2️⃣ Pinecone
🔹 Background
●​ Founded: 2019
●​ Founder: Iddo Liberty (ex-AWS & Yahoo!)
●​ Built for: recommendation systems, spam detection

🔹 What It Is
●​ Fully managed vector database
●​ Designed to simplify similarity search at scale

✅ Strengths
●​ No infrastructure management
●​ Automatic scaling
●​ High performance on large datasets
●​ Clean, intuitive API
●​ Beginner-friendly

❌ Weaknesses
●​ Limited customization
●​ More expensive at scale
●​ Less control than self-hosted solutions

📌 Best For
●​ Beginners
●​ Rapid prototyping
●​ Production-ready semantic search systems

3️⃣ Milvus
🔹 Background
●​ Open source
●​ Developed by Zilliz
●​ Focused on large-scale similarity search
✅ Strengths
●​ Fully open source
●​ Extremely customizable
●​ Handles billions of vectors
●​ Multiple indexing methods
●​ Supports hybrid (vector + traditional) search

❌ Weaknesses
●​ Steep learning curve
●​ Requires strong system & ML knowledge
●​ Infrastructure management is on you

📌 Best For
●​ Advanced users
●​ Large-scale, custom AI systems

4️⃣ Weaviate (called “Deviate” in narration)


🔹 Background
●​ Founded: 2018, Netherlands
●​ Open source

🔹 Key Idea
●​ Combines vector search + graph database

✅ Strengths
●​ Contextual & semantic search
●​ Built-in ML models for auto-vectorization
●​ GraphQL & REST APIs
●​ Rich data relationships

❌ Weaknesses
●​ Newer → fewer advanced features
●​ Graph + vector combo can impact performance at scale

📌 Best For
●​ Knowledge graphs
●​ Context-aware AI applications

5️⃣ Qdrant (called “Quadrant”)


🔹 Background
●​ Founded: 2020
●​ Open source, performance-focused

✅ Strengths
●​ High throughput & low latency
●​ Custom indexing strategies
●​ Payload filtering (metadata-based filtering)
●​ Custom ranking logic (not just similarity)

❌ Weaknesses
●​ More complex setup
●​ Requires tuning for best performance
●​ Smaller community & documentation

📌 Best For
●​ High-performance search
●​ Advanced ranking & filtering needs

6️⃣ Why Pinecone Was Chosen for This Course


●​ Easiest to get started
●​ Minimal setup
●​ Strong performance
●​ Ideal for learning concepts without infra headaches

7️⃣ Pinecone Platform Basics


🔹 Registration
●​ Sign up at [Link]
●​ Passwordless login (email verification code)
●​ Supports multiple organizations

🔹 Workspace Concepts
●​ Workspace → top-level environment
●​ Project → logical grouping (free plan = 1)
●​ Index → actual vector store

🔹 Free (Starter) Plan Limits


●​ 1 workspace
●​ 1 project
●​ Up to 5 indexes

8️⃣ API Keys


●​ Required to connect via Python
●​ Must be kept secret
●​ Can be regenerated if compromised

9️⃣ What Is an Index?


●​ A vector store + configuration
●​ Defines:
○​ Number of dimensions
○​ Similarity metric (cosine / dot product)
●​ All vectors in an index must match the dimension size

🔟 Connecting to Pinecone with Python


Key Practices

●​ Use a .env file for:


○​ API key
○​ Environment name
●​ Never hardcode credentials
●​ Improves security & reusability

Environment Used
●​ Free plan → gcp-starter

1️⃣1️⃣Managing Indexes in Python


Common Operations

●​ List indexes
●​ Create index
●​ Delete index
●​ Check existence before creation (best practice)

Why Manage in Code?

●​ Automation
●​ Reproducibility
●​ Scalable workflows

1️⃣2️⃣Upserting Data
🔹 What “Upsert” Means
●​ Update if vector exists
●​ Insert if vector is new

Format

●​ List of tuples:
○​ (id, vector, metadata)

1️⃣3️⃣Simple Vector Example (Animals)


●​ Dimensions: 3
○​ Legs
○​ Wings
○​ Tails
●​ Demonstrates:
○​ Similarity search
○​ Cosine distance behavior
●​ Key lesson:
○​ Poor features = misleading similarity
○​ Data quality matters more than database choice

1️⃣4️⃣Scaling Dimensions
●​ Real embeddings often have:
○​ 384
○​ 768
○​ 1536 dimensions
●​ High dimensions = richer semantic meaning

1️⃣5️⃣Large-Scale Data Upload (Hugging Face)


Dataset Used

●​ FineWeb
●​ Trillions of tokens (sampled)
●​ Fields include:
○​ Text
○​ ID
○​ URL
○​ Date
○​ Language score

Why Iterable Datasets?

●​ Memory efficient
●​ Stream data instead of loading everything

1️⃣6️⃣Embeddings
●​ Embeddings convert text → vectors
●​ All vectors:
○​ Same dimension
○​ Determined by embedding model
●​ Example used:
○​ Fast embedding model
○​ Dimension = 384
1️⃣7️⃣Batch Upserting
Why Batching?

●​ Faster uploads
●​ Reduced memory pressure

Trade-off

●​ Large batch → faster but memory-heavy


●​ Small batch → safer but slower

1️⃣8️⃣Handling Very Large Data


●​ Full dataset upload can take hours
●​ Solution:
○​ Sample a subset (e.g. 10,000 entries)
○​ Still demonstrates full pipeline
●​ Practical takeaway:
○​ Real-world systems often ingest data incrementally

🔑 Key Takeaways
●​ Vector DB choice depends on:
○​ Scale
○​ Control
○​ Expertise
●​ Pinecone = fastest path to production
●​ Embeddings define your entire system
●​ Data quality > similarity metric
●​ Large-scale vector systems require batching & sampling

📘 Practical Case Study: Semantic


Search with Pinecone
(End-to-End Detailed Notes)
1️⃣ What Problem Are We Solving?
❌ Problem with Traditional Search
●​ Traditional search relies on exact keyword matching
●​ Results are:
○​ Ordered by recency, not relevance
○​ Miss content if wording doesn’t match exactly


●​ Synonyms, abbreviations, and paraphrases fail:
○​ Queen Elizabeth Retrospective
○​ Article titled Elizabeth II and the Monarch’s Life and Reign ❌
Why This Happens

●​ Traditional databases:
○​ Tabular (rows & columns)
○​ SQL / NoSQL based
○​ Match strings literally
●​ No understanding of meaning

2️⃣ What Is Semantic (Similarity) Search?


✅ Definition
Semantic search retrieves results based on meaning, not exact words.

How It Works

●​ Text is converted into vectors


●​ Vectors with similar meaning are close in vector space
●​ Example:
○​ Queen ↔ Monarch
○​ Elizabeth II ↔ Late Queen
●​ Even if words differ → meaning aligns → result retrieved

3️⃣ Why Vector Databases Are Needed


●​ Vector DBs store embeddings
●​ Enable:
○​ Fast similarity search
○​ Scalable retrieval
○​ Context-aware results
●​ Unlike relational DBs:
○​ They don’t use joins
○​ They rely on distance metrics (cosine, dot product)

4️⃣ Why Not Replace Traditional Databases?


Reality Check

●​ Most business data is:


○​ Relational
○​ Semi-structured
●​ Vector DBs are not replacements
●​ They augment traditional systems

Common Hybrid Setup

●​ SQL / NoSQL → structured data


●​ Vector DB → semantic text search
●​ Best of both worlds

5️⃣ Case Study Context: 365 Platform Search


Current Issues

●​ Exact match only


●​ Abbreviations fail (ML ≠ Machine Learning)
●​ Section-level content is invisible
●​ Course titles are short → lack detail

Example Failure

●​ Query: unsupervised learning in Python


●​ Result: ❌ none
●​ But content exists in:
○​ Customer Analytics in Python
○​ ML in Python
○​ Other courses
6️⃣ Case Study Goal
Build a semantic search system that:

●​ Finds relevant courses & sections


●​ Understands meaning, not wording
●​ Works even when:
○​ Keywords differ
○​ Topics are spread across sections

7️⃣ Case Study Game Plan


1.​ Define the problem
2.​ Explore the dataset
3.​ Preprocess tabular data
4.​ Create embeddings
5.​ Upload vectors to Pinecone
6.​ Query semantically
7.​ Improve results with:
○​ Better data
○​ Better embeddings
○​ Thresholding
○​ Metadata
○​ Weights

8️⃣ Dataset (Course-Level)


Columns

●​ Course name
●​ Technology (only one, limitation)
●​ Topics (predefined list)
●​ Short description
●​ Long description

Data Limitations

●​ Multiple technologies → only one stored


●​ Topics are vague
●​ Course titles are concise (UI reasons)

➡️ Conclusion: We must enrich context manually.


9️⃣ Data Preprocessing Strategy
Key Insight

Vectors can handle long, contextual text better than single columns.

Instead of:

●​ One vector per column ❌


We do:

●​ Merge columns into one descriptive string ✅

🔟 Creating a Unified Course Description


Function Logic

●​ Combine:
○​ Course name
○​ Slug
○​ Technology
○​ Topics
○​ Descriptions
●​ Use natural language sentences
●​ Not raw concatenation

Why?

●​ LLM embeddings benefit from:


○​ Context
○​ Narrative flow
○​ Rich text

1️⃣1️⃣Environment Setup (Security)

.env File

Stores:
●​ Pinecone API Key
●​ Pinecone environment (gcp-starter)

Why?

●​ Never hardcode secrets


●​ Safe for GitHub
●​ Industry best practice

1️⃣2️⃣Connecting to Pinecone
Steps:

1.​ Load environment variables (dotenv)


2.​ Initialize Pinecone client
3.​ Connect to index
4.​ Verify connection

1️⃣3️⃣Embedding Algorithms (Theory)


Traditional NLP

●​ Bag of Words


●​ TF-IDF​
No context awareness

Neural Embeddings

●​ Word2Vec (CBOW & Skip-Gram)


●​ ELMo (Bi-LSTM, contextual)
●​ BERT (Transformers, attention)

Key Evolution

NLP → Neural Nets → LLMs

1️⃣4️⃣Sentence Transformers
●​ Pretrained models optimized for:
○​ Semantic search
○​ Speed vs accuracy tradeoffs
●​ Metrics:
○​ Dimension size
○​ Performance score
○​ Latency

Initial Choice

●​ 384-dimension model
●​ Fast & lightweight
●​ Good baseline

1️⃣5️⃣Creating Embeddings
Process

1.​ Merge text fields


2.​ Encode text using model
3.​ Output numeric vectors
4.​ Store as NumPy arrays

Why Batch Encoding?

●​ Faster
●​ Cleaner
●​ Scalable

1️⃣6️⃣Uploading to Pinecone
Vector Format

(id, vector, metadata)

●​ ID: course name


●​ Vector: embedding
●​ Metadata: optional (later added)

Result

●​ All courses successfully stored


●​ Vectors searchable by similarity
1️⃣7️⃣First Semantic Query (Course-Level)
Query

clustering

Steps

1.​ Embed query


2.​ Query Pinecone index
3.​ Retrieve top-k results
4.​ Inspect scores

Issues Observed

●​ Some irrelevant results ranked high


●​ KNN appears due to semantic overlap
●​ Data still too coarse

➡️ Conclusion: Embeddings aren’t the problem — data granularity is.

1️⃣8️⃣Key Insight: Garbage In, Garbage Out


●​ No embedding can fix:
○​ Poor data
○​ Missing context
●​ Course titles alone are insufficient
●​ Sections contain the real value

1️⃣9️⃣Section-Level Dataset
New Columns Added

●​ Section ID
●​ Section name
●​ Section description

Structure

●​ Course info duplicated per section


●​ Each row = course + one section

2️⃣0️⃣Two Design Approaches


Approach 1 (Exercise)

●​ Aggregate course + all sections into one blob

Approach 2 (Used)

●​ One vector per course-section pair

➡️ Chosen for:
●​ Granularity
●​ Precision
●​ Better recall

2️⃣1️⃣Metadata Design
Metadata includes:

●​ Course name
●​ Section name
●​ Section description

Why Metadata Matters

●​ Vectors are unreadable to humans


●​ Metadata provides:
○​ Transparency
○​ Debugging
○​ User trust

2️⃣2️⃣Section-Level Embeddings
●​ Merge:
○​ Course info
○​ Section info
●​ Encode with same model (384 dims)
●​ Create new embeddings column
●​ Upsert into Pinecone

Result:

●​ ~600 vectors in database

2️⃣3️⃣Section-Level Semantic Search


Query

clustering

Improvements

●​ Correct sections appear


●​ K-means, hierarchical clustering detected
●​ Multiple courses retrieved correctly

Remaining Noise

●​ Intro sections
●​ Semantically adjacent topics (decision trees)

2️⃣4️⃣Score Thresholding
●​ Example threshold: 0.3
●​ Purpose:
○​ Remove weak matches
●​ Trade-off:
○​ Higher → precision
○​ Lower → recall

2️⃣5️⃣Trying Better Embeddings


Upgrade

●​ 768-dimension model
●​ Trained specifically for semantic search

Required Changes
●​ New index
●​ Updated dimension count
●​ Re-embedding data

2️⃣6️⃣Results After Upgrade


Query

regression

Outcome

●​ Ridge & Lasso Regression (top result)


●​ Python-based regression courses retrieved
●​ Section-level relevance improved significantly

➡️ Major win

2️⃣7️⃣Final Enhancement: Weighted Search


Problem

●​ All text treated equally


●​ Course name ≠ section description importance

Solution

●​ Apply weights to:


○​ Course name
○​ Section name
○​ Section description
●​ Experiment with combinations

2️⃣8️⃣Beyond Semantic Search


Recommendation Systems

●​ Item-based
●​ User-based
●​ Vector similarity enables:
○​ Amazon-style recommendations
○​ Cross-interest discovery

2️⃣9️⃣Image Search
●​ Images → vectors using CNNs / Siamese networks
●​ Enables:
○​ Face recognition
○​ Visual product search
○​ Fashion & furniture matching

3️⃣0️⃣Biomedical Research
Applications

●​ Gene similarity
●​ Protein interactions
●​ Drug discovery

Why Vectors Matter

●​ Encode molecular structure


●​ Encode biological activity
●​ Search similar compounds efficiently

➡️ Faster discovery, lower cost, personalized medicine

🔑 Final Takeaways
●​ Semantic search ≠ keyword search
●​ Embeddings + data quality = results
●​ Granularity matters more than models
●​ Vector DBs augment, not replace SQL
●​ Pinecone enables fast, scalable similarity search
●​ Understanding internals > treating tools as black boxes

You might also like