If you’re diving into AI and LLMs, you’ve probably heard about vector databases. But what exactly makes a vector database different from your everyday SQL or NoSQL solution? And how do they fit into the AI/ML ecosystem?
In this post, we’ll explore the application of vector databases, particularly in the context of AI and machine learning workflows.
Traditional databases store data in structured (SQL) or semi-structured/unstructured (NoSQL) formats, optimised for querying text, numbers, and relational data. But AI applications—especially those using embeddings—need something different.
Vector databases store high-dimensional vector embeddings generated by AI models (e.g., OpenAI’s text-embedding-ada-002
). These embeddings capture semantic meaning, allowing for efficient similarity searches, recommendation systems, and retrieval-augmented generation (RAG) in LLMs.
Instead of exact matches (like SQL queries), vector DBs use distance metrics (cosine similarity, Euclidean distance, etc.) to retrieve the most relevant data points based on context.
Can’t you just store vectors in a traditional database? Technically, yes. PostgreSQL’s pgvector
extension and MongoDB’s Atlas Vector Search offer some capabilities, but they aren’t built from the ground up for vector-heavy workloads.
Popular Vector Database Solutions
Here are some standout vector databases, and some short examples of how to use it with Langchain.
Example: Storing and retrieving embeddings with Pinecone + LangChain.
from langchain.vectorstores import Pineconefrom langchain.embeddings.openai import OpenAIEmbeddingsimport pineconepinecone.init(api_key="your-api-key", environment="us-west1-gcp")index_name = "my-langchain-index"vectorstore = Pinecone(index_name, OpenAIEmbeddings())query_result = vectorstore.similarity_search("What is vector search?")print(query_result)
Example: Inserting and searching data in Weaviate.
import weaviateclient = weaviate.Client("http://localhost:8080")client.schema.create({"class": "Article", "vectorIndexType": "hnsw"})client.data_object.create({"text": "Introduction to AI"}, "Article")query_result = client.query.get("Article", ["text"]).with_near_text({"concepts": ["AI"]}).do()print(query_result)
Example:
from langchain.vectorstores import Chromafrom langchain.embeddings.openai import OpenAIEmbeddingsvectorstore = Chroma(collection_name="my_collection", embedding_function=OpenAIEmbeddings())query_result = vectorstore.similarity_search("What is vector search?")print(query_result)
Big players in the database world aren’t sitting idle. Many are adding vector search features to their existing platforms to support AI-driven applications.
pgvector
)
As AI applications scale, vector databases are becoming crucial for efficiently retrieving and using embeddings in LLM workflows. Whether you’re building a chatbot, recommendation system, or AI-powered search, choosing the right vector database is key to unlocking the full potential of your data.
Which one are you most excited to experiment with? Let’s discuss!
\ How vector databases power AI search
Mongo Atlas Vector Search Quick Start
Quick Links
Legal Stuff