Bird
Raised Fist0
Agentic AIml~10 mins

Vector store selection (Pinecone, Chroma, FAISS) in Agentic AI - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize a FAISS vector store.

Agentic AI
from langchain.vectorstores import FAISS
vector_store = FAISS.from_texts(texts, embeddings, index_factory=[1])
Drag options to blanks, or click blank then click option'
A"Pinecone"
B"Flat"
C"Chroma"
D"Annoy"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Pinecone' or 'Chroma' as FAISS index factory names.
Leaving the index_factory parameter empty.
2fill in blank
medium

Complete the code to create a Chroma vector store with a persist directory.

Agentic AI
from langchain.vectorstores import Chroma
vector_store = Chroma.from_texts(texts, embeddings, persist_directory=[1])
Drag options to blanks, or click blank then click option'
A"./chroma_db"
BNone
C"/tmp/faiss"
D"pinecone_index"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None or invalid paths to persist_directory.
Using paths meant for other vector stores like FAISS or Pinecone.
3fill in blank
hard

Fix the error in the Pinecone initialization code by completing the missing parameter.

Agentic AI
import pinecone
pinecone.init(api_key=[1], environment="us-west1-gcp")
Drag options to blanks, or click blank then click option'
A12345
BNone
C"your-pinecone-api-key"
D"chroma"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing None or numeric values as api_key.
Confusing environment names with API keys.
4fill in blank
hard

Fill both blanks to create a FAISS vector store and save it to disk.

Agentic AI
from langchain.vectorstores import FAISS
vector_store = FAISS.from_texts(texts, embeddings, index_factory=[1])
vector_store.[2]("faiss_index")
Drag options to blanks, or click blank then click option'
A"Flat"
Bsave_local
Csave_local_index
Dsave
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like 'save' or 'save_local_index'.
Using wrong index factory names.
5fill in blank
hard

Fill all three blanks to create a Pinecone vector store client with index name and namespace.

Agentic AI
import pinecone
pinecone.init(api_key=[1], environment=[2])
index = pinecone.Index(name=[3])
Drag options to blanks, or click blank then click option'
A"your-pinecone-api-key"
B"us-west1-gcp"
C"my-index"
D"chroma"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up environment and index name strings.
Using invalid API key formats.

Practice

(1/5)
1.

Which vector store is best known for easy cloud-based deployment and scalability?

easy
A. Pinecone
B. Chroma
C. FAISS
D. Local file system

Solution

  1. Step 1: Understand cloud-based vector stores

    Pinecone is designed as a managed cloud service, making deployment and scaling easy.
  2. Step 2: Compare with other options

    Chroma and FAISS are typically used locally or self-hosted, not primarily cloud services.
  3. Final Answer:

    Pinecone -> Option A
  4. Quick Check:

    Cloud deployment = Pinecone [OK]
Hint: Cloud + scalability? Think Pinecone first [OK]
Common Mistakes:
  • Confusing FAISS as cloud service
  • Assuming Chroma is cloud-only
  • Choosing local file system as vector store
2.

Which of the following is the correct way to initialize a FAISS index for 128-dimensional vectors in Python?

import faiss
index = faiss.IndexFlatL2(____)
easy
A. '128'
B. IndexFlatL2(128)
C. faiss.IndexFlatL2(128)
D. 128

Solution

  1. Step 1: Understand FAISS index initialization

    The IndexFlatL2 constructor expects an integer dimension, not a string or nested call.
  2. Step 2: Check the correct argument type

    Passing 128 as an integer is correct; quotes or extra calls cause errors.
  3. Final Answer:

    128 -> Option D
  4. Quick Check:

    Dimension as int = 128 [OK]
Hint: Dimension must be integer, no quotes [OK]
Common Mistakes:
  • Passing dimension as string
  • Calling constructor inside argument
  • Using undefined names without import
3.

Given this code snippet using Chroma vector store, what will be the output?

from chromadb import Client
client = Client()
collection = client.create_collection('test')
collection.add(ids=['1'], embeddings=[[0.1, 0.2]], metadatas=[{'name': 'item1'}], documents=['doc1'])
results = collection.query(query_embeddings=[[0.1, 0.2]], n_results=1)
print(results['documents'])
medium
A. [['doc1']]
B. ['doc1']
C. [{'name': 'item1'}]
D. Error: missing parameters

Solution

  1. Step 1: Understand Chroma query output format

    The query returns a dictionary with keys like 'documents' containing a list of lists of matched documents.
  2. Step 2: Check the printed output

    Printing results['documents'] shows a list containing a list with 'doc1', so output is [['doc1']].
  3. Final Answer:

    [['doc1']] -> Option A
  4. Quick Check:

    Chroma query docs = [['doc1']] [OK]
Hint: Chroma query returns list of lists for documents [OK]
Common Mistakes:
  • Expecting flat list instead of nested list
  • Confusing metadata with documents
  • Assuming query returns error without reason
4.

What is the main error in this FAISS usage code snippet?

import faiss
index = faiss.IndexFlatL2(64)
vectors = [[0.1]*64, [0.2]*64]
index.add(vectors)
print(index.ntotal)
medium
A. Vectors length must be 63, not 64
B. Vectors must be a numpy array of type float32
C. ntotal is not a valid attribute
D. Index dimension should be 128, not 64

Solution

  1. Step 1: Check vector data type for FAISS

    FAISS requires vectors as numpy arrays with dtype float32, not Python lists.
  2. Step 2: Identify the error cause

    Passing a list causes a type error; converting to numpy float32 fixes it.
  3. Final Answer:

    Vectors must be a numpy array of type float32 -> Option B
  4. Quick Check:

    FAISS vectors = numpy float32 array [OK]
Hint: FAISS needs numpy float32 arrays, not lists [OK]
Common Mistakes:
  • Using Python lists instead of numpy arrays
  • Wrong dimension assumption
  • Misunderstanding ntotal attribute
5.

You have a large dataset of 10 million vectors and want fast similarity search on your local machine without internet. Which vector store is the best choice?

hard
A. Pinecone
B. Chroma
C. FAISS
D. SQLite database

Solution

  1. Step 1: Consider dataset size and environment

    10 million vectors is large; local machine without internet means no cloud services.
  2. Step 2: Match vector store to requirements

    FAISS is optimized for large-scale local similarity search and does not require internet.
  3. Step 3: Exclude other options

    Pinecone is cloud-based, Chroma is less optimized for huge local datasets, SQLite is not a vector store.
  4. Final Answer:

    FAISS -> Option C
  5. Quick Check:

    Large local dataset = FAISS [OK]
Hint: Big local data? Choose FAISS for speed [OK]
Common Mistakes:
  • Choosing cloud-based Pinecone for offline use
  • Assuming Chroma handles huge data best locally
  • Using SQLite as vector store