Modal Title
AI / Data / Machine Learning

Vector Databases: Long-Term Memory for Artificial Intelligence

Vector databases store data such as text, video or images that are converted into vector embeddings for AI models to access them quickly.
May 12th, 2023 7:00am by
Featued image for: Vector Databases: Long-Term Memory for Artificial Intelligence
Image by tikisada from Pixabay. 

Artificial Intelligence, such as ChatGPT, acts much like someone with endemic memory who goes to a library and reads every book. However, when you ask an AI a question that was not in the book at the library, it either admits it doesn’t know or hallucinates.

An AI hallucination refers to instances where an artificial intelligence system generates an output that may seem coherent or plausible but is not grounded in reality or accurate information. These outputs can include text, images or other forms of data that the AI model has produced based on its training but may not align with real-world facts or logic.

For example, we could use a generative AI for images like the ones Midjourney provides to generate a picture of an old man. However, the prompt (the way you communicate with an AI like Stable Diffusion or others) has to be something that the model understands. For example, you may ask the AI to create a picture of a man who is over the hill. In this case, I used Midjourney, a popular generative AI for images, to do just that. I used an example that I thought might cause it to hallucinate.

Midjourney-generated image of a man over the hill

Midjourney doesn’t understand euphemisms like over the hill, so it generated a picture of a man who was literally over the top of a hill.

How could you inform the AI what you mean by “over the hill,” and other nuances of language it doesn’t know of? First, you could provide training data. The way you would do this is to convert that data into something known as embeddings, and then import them into a vector database.

While this example is a bit far-fetched for effect, many other contexts apply. For example, industry-specific terminology for medical and legal fields would benefit from being able to train AI on their specific terminology and meanings. Enterprises will want to provide their data to AI without introducing public models.

A critical use case for vector databases is large language models to retrieve domain-specific or proprietary facts that can be queried during text generation. Therefore, vector databases will be essential for organizations building proprietary large language models.

Vector vs. NoSQL and SQL Databases

Traditional databases, such as relational databases (e.g., MySQL, PostgreSQL, Oracle) and NoSQL databases (e.g., MongoDB, Cassandra), have been the backbone of business data management for decades. They store and organize data in structured formats like tables, documents or key-value pairs, making it easier to query and manipulate using standard programming languages.

These databases excel at handling structured data with fixed schema, but they often struggle with unstructured data or high-dimensional data, such as images, audio and text. Moreover, as the volume and velocity of data increase, they may face performance bottlenecks, leading to slower response times and scalability issues.

Vector databases, on the other hand, represent a paradigm shift in data storage and retrieval. Instead of relying on structured formats, they store and index data as mathematical vectors in high-dimensional space. This approach, called “vectorization,” allows for more efficient similarity searches and better handling of complex data types, such as images, audio, video and natural language.

Imagine a vector database as a vast warehouse and the AI as the skilled warehouse manager. In this warehouse, every item (data) is stored in a box (vector), organized neatly on shelves in a multidimensional space. The warehouse manager (AI) knows the exact position of each box and can quickly retrieve or compare the items based on their similarities, just like a skilled warehouse manager can find similar group products.

The boxes represent different types of unstructured data, such as text, images or audio, which have been transformed into a structured numerical format (vectors) to be efficiently stored and managed. The more organized and optimized the warehouse is, the faster and more accurately the warehouse manager (AI) can find the items needed for various tasks, such as making recommendations, recognizing patterns or detecting anomalies.

This analogy helps convey the idea that vector databases serve as a crucial foundation for AI systems, enabling them to efficiently manage, search and process complex data in a structured and organized manner. Just as a well-managed warehouse is essential for smooth business operations, a vector database plays a vital role in the success of AI-driven applications and solutions.

The key advantage of vector databases is their ability to perform approximate nearest neighbor (ANN) search, quickly identifying similar items in a large dataset. Using techniques like dimensionality reduction and indexing algorithms, vector databases can perform these searches at scale, providing lightning-fast response times and making them ideal for applications like recommendation systems, anomaly detection and natural language processing.

Embeddings — Turning Words, Images and Videos into Numbers

Embeddings are techniques that convert complex data, such as words, into simpler numerical representations (called vectors). This makes it easier for AI systems to understand and work with the data. Probability helps create these representations by analyzing how often certain pieces of data appear together.

Probability helps quantify the similarity of two pieces of data, allowing the AI system to find related items. Probability-based techniques help AI systems quickly find similar data points in large databases without examining every item. Probability helps AI systems group similar data points together and reduce the complexity of the data, making it easier to process and analyze.

Popular Vector Databases

While there are an ever-growing number of vector databases, several factors contribute to their popularity. These factors include efficient performance in storing, indexing and searching high-dimensional vectors, ease of use in integrating with existing machine learning frameworks and libraries, scalability in handling large-scale, high-dimensional data, flexibility in offering multiple backends and indexing algorithms, and active community support with valuable resources, tutorials and examples.

Vector databases that are more likely to be popular among users are ones that provide fast and accurate nearest-neighbor search, clustering, and similarity matching, and that can be easily deployed on cloud infrastructure or distributed computing systems. Based on popularity among users and the number of stars on Github, here are some of the most popular vector databases.

  • Pinecone: Pinecone is a cloud-based vector database designed to efficiently store, index and search extensive collections of high-dimensional vectors. Pinecone’s key features include real-time indexing and searching, handling sparse and dense vectors, and support for exact and approximate nearest-neighbor search. In addition, Pinecone can be easily integrated with other machine learning frameworks and libraries, making it popular for building production-grade NLP and computer vision applications.
  • Chroma: Chroma is an open source vector database that provides a fast and scalable way to store and retrieve embeddings. Chroma is designed to be lightweight and easy to use, with a simple API and support for multiple backends, including RocksDB and Faiss (Facebook AI Similarity Search — a library that allows developers to quickly search for embeddings of multimedia documents that are similar to each other). Chroma’s unique features include built-in support for compression and quantization, as well as the ability to dynamically adjust the size of the database to handle changing workloads. Chroma is a popular choice for research and experimentation due to its flexibility and ease of use.
  • Weaviate: Weaviate is an open source vector database designed to build and deploy AI-powered applications. Weaviate’s key features include support for semantic search and knowledge graphs and the ability to automatically extract entities and relationships from text data. Weaviate also includes built-in support for data exploration and visualization. Weaviate is an excellent choice for applications that require complex semantic search or knowledge graph functionality.
  • Milvus: Milvus is an open source vector database designed for large-scale machine-learning applications. Milvus is optimized for both CPU and GPU-based systems and supports exact and approximate nearest-neighbor searches. Milvus also includes a built-in RESTful API and support for multiple programming languages, including Python and Java. Milvus is a popular choice for building recommendation engines and search systems that require real-time similarity searches. Milvus is part of the Linux Foundation’s AI and Data Foundation, but the primary developer is Zilliz.
  • DeepLake: DeepLake is a cloud-based vector database that is designed for machine learning applications. DeepLake’s unique features include built-in support for streaming data, real-time indexing and searching, and the ability to handle both dense and sparse vectors. DeepLake also provides a RESTful API and support for multiple programming languages. DeepLake is a good choice for applications that require real-time indexing and search of large-scale, high-dimensional data.
  • Qdrant: Qdrant is an open source vector database designed for real-time analytics and search. Qdrant’s unique features include built-in support for geospatial data and the ability to perform geospatial queries. Qdrant also supports exact and approximate nearest-neighbor searches and includes a RESTful API and support for multiple programming languages. Qdrant is an excellent choice for applications that require real-time geospatial search and analytics.

As in the case of SQL and NoSQL databases, vector databases come in many different flavors and address various use cases.

Use Cases for Vector Databases

Artificial intelligence applications rely on efficiently storing and retrieving high-dimensional data to provide personalized recommendations, recognize visual content, analyze text and detect anomalies. Vector databases enable efficient and accurate search and analysis of high-dimensional data, making them essential for developing robust and efficient AI systems.

Recommender Systems

In recommender systems, vector databases have the crucial function of storing and proposing items that best match users’ interests and preferences. These databases facilitate fast and effective searches for similar items by representing items as vectors. This feature allows AI-powered systems to provide personalized recommendations, thus improving user experiences on social networks, streaming services and e-commerce websites.

One commonly used AI-powered recommendation system is the one used by Amazon. Amazon uses a collaborative filtering algorithm that analyzes customer behavior and preferences to make personalized recommendations for products they might be interested in purchasing.

This system considers past purchase history, search queries and items in the customer’s shopping cart to make recommendations. Amazon’s recommendation system also uses natural language-processing techniques to analyze product descriptions and customer reviews to provide more accurate and relevant recommendations.

Image and Video Recognition

In image and video recognition, vector databases store visual content as high-dimensional vectors. These databases empower AI models to efficiently recognize and understand images or videos, find similarities, and perform object recognition, face recognition, or image classification tasks. This has applications in security and surveillance, autonomous vehicles and content moderation.

One commonly used image and video recognition system powered by AI is the TensorFlow Object Detection API. This open source framework developed by Google allows users to train their own models for object detection tasks, such as identifying and localizing objects within images and videos.

The TensorFlow Object Detection API uses deep learning models, such as the popular Faster R-CNN and SSD models, to achieve high accuracy in object detection. It also provides pre-trained models for everyday object detection tasks, which can be fine-tuned on new datasets to improve performance.

Natural Language Processing (NLP)

Vector databases play a critical role in NLP by storing and managing information about words and sentences as vectors. These databases enable AI systems to perform tasks such as searching for related content, analyzing the sentiment of a piece of text or even generating human-like responses. By harnessing the power of vector databases, NLP models can be used for applications like chatbots, sentiment analysis or machine translation.

One commonly used NLP system is the Natural Language Toolkit (NLTK). NLTK is a comprehensive platform for building Python programs to work with human language data. It provides easy-to-use interfaces to over 50 corpora and lexical resources and a suite of text-processing libraries for classification, tokenization, stemming, tagging, parsing, semantic reasoning and more. Researchers and practitioners widely use NLTK in academia and industry, and it is a popular choice for teaching NLP concepts and techniques.

Anomaly Detection

Vector databases can help detect unusual activities or behaviors in various areas, such as cybersecurity, fraud detection or industrial equipment monitoring. These databases can quickly identify patterns that deviate from the norm by representing data as vectors. AI models integrated with vector databases can then flag these anomalies and trigger alerts or mitigation measures, ensuring timely and effective responses.

Microsoft Azure Anomaly Detector is a cloud-based service that allows users to monitor and analyze time series data to identify anomalies, spikes and other unusual patterns. Azure Anomaly Detector uses advanced AI algorithms such as Seasonal Hybrid ESD (S-H-ESD) and Singular Spectrum Analysis (SSA) to automatically detect and alert users when anomalous behavior is caught in the data. It also provides a simple REST API for developers to integrate the service into their applications and workflows efficiently.

Summary

Vector databases are critical to many artificial intelligence (AI) applications, including recommender systems, image and video recognition, natural language processing (NLP) and anomaly detection. By storing and managing data as high-dimensional vectors, these databases enable efficient and accurate search and analysis of large datasets, leading to enhanced user experiences, improved automation, and timely detection of anomalies. In the realm of recommender systems, vector databases allow for the quick identification of items most relevant to users’ preferences.

At the same time, image and video recognition enables efficient object and face recognition. Vector databases play a crucial role in NLP by storing and managing information about words and sentences as vectors. In anomaly detection, they enable quick identification of unusual patterns or behaviors. Overall, vector databases are essential for developing robust and efficient AI systems across various domains.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.