</>
Skip to content
Gen AI lessons (12/39)

Gen AI — Vector Databases

What are vector databases?

Databases optimized for storing and searching high-dimensional vectors.

Popular options

DatabaseTypeBest For
PineconeManagedProduction
ChromaDBLocalDevelopment
FAISSLibraryResearch
WeaviateSelf-hostedFlexibility

ChromaDB

import chromadb

client = chromadb.Client()
collection = client.create_collection("documents")

# Add documents
collection.add(
    documents=["Hello world", "How are you?"],
    ids=["doc1", "doc2"]
)

# Query
results = collection.query(
    query_texts=["greeting"],
    n_results=2
)

Pinecone

from pinecone import Pinecone

pc = Pinecone(api_key="your-key")
index = pc.Index("my-index")

# Upsert vectors
index.upsert(vectors=[
    {"id": "doc1", "values": embedding1, "metadata": {"text": "Hello"}},
    {"id": "doc2", "values": embedding2, "metadata": {"text": "World"}}
])

# Query
results = index.query(
    vector=query_embedding,
    top_k=5,
    include_metadata=True
)

FAISS

import faiss
import numpy as np

dimension = 1536
index = faiss.IndexFlatL2(dimension)

# Add vectors
vectors = np.array([...]).astype('float32')
index.add(vectors)

# Search
distances, indices = index.search(query_vector, k=5)

Mini Practice

  1. Set up ChromaDB locally
  2. Store and query embeddings
  3. Compare vector databases
  4. Build a semantic search app

Up Next

Continue with RAG - Retrieval-Augmented Generation.

Related Topics

Frequently Asked Questions about Vector Databases

What is Vector Databases in Gen AI?

Vector Databases is a fundamental concept in Gen AI. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Vector Databases?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Vector Databases.

Why is Vector Databases important in Gen AI?

Vector Databases is essential for Gen AI development. Understanding this concept will help you write better code and solve real-world problems more effectively.