Vector stores help us quickly find similar items by comparing their numbers. Choosing the right one makes searching faster and easier.
Vector store selection (Pinecone, Chroma, FAISS) in Agentic AI
vector_store = VectorStoreType(parameters) results = vector_store.search(query_vector, top_k)
Replace VectorStoreType with Pinecone, Chroma, or FAISS depending on your needs.
parameters include things like API keys, index names, or file paths.
import pinecone pinecone.init(api_key='your_key') index = pinecone.Index('example-index') results = index.query(query_vector, top_k=5)
from chromadb import Client client = Client() collection = client.get_collection('my_collection') results = collection.query(query_vector=query_vector, n_results=3)
import faiss index = faiss.IndexFlatL2(dimension) index.add(data_vectors) D, I = index.search(query_vector, k=4)
This program creates a small set of 3D vectors, builds a FAISS index, and searches for the 2 closest vectors to the query. It prints distances and indices of the closest matches.
import numpy as np import faiss # Create some example data vectors (5 vectors, 3 dimensions each) data_vectors = np.array([ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0], [1.0, 1.0, 0.0], [0.0, 1.0, 1.0] ], dtype='float32') # Build FAISS index index = faiss.IndexFlatL2(3) # 3 is the dimension index.add(data_vectors) # Query vector query_vector = np.array([[1.0, 0.0, 0.0]], dtype='float32') # Search top 2 nearest neighbors D, I = index.search(query_vector, 2) print('Distances:', D) print('Indices:', I)
Pinecone is a cloud service, so you need an internet connection and API key.
Chroma is easy to use locally and good for small to medium data sets.
FAISS is very fast and works well for large data but needs more setup.
Vector stores help find similar data quickly using numbers.
Pinecone, Chroma, and FAISS each have strengths for different needs.
Choose based on your data size, speed needs, and whether you want cloud or local storage.