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. Additionally, we’ll examine how they integrate with LangChain, a popular framework for building applications with large language models (LLMs).
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.
LangChain is an open-source framework designed for building applications that integrate large language models (LLMs) with external data sources such as vector databases, APIs, and traditional databases.
It provides tools for managing AI workflows, including retrieval-augmented generation (RAG), document indexing, and chatbot development.
We’re mentioning LangChain because it simplifies working with vector databases, making it easier to retrieve and use embeddings in AI applications. If you’re working with LLMs, LangChain provides pre-built integrations with several vector databases, reducing the complexity of setting up search and retrieval functionalities.
For more details, you can check out the LangChain documentation.
Here are some standout vector databases, how they work, and their integration 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!
Vector Database with Pinecone\ How vector databases power AI search
Mongo Atlas Vector Search Quick Start\ Weaviate Quickstart