Databases store vectors used by Large Language Models (LLMs) typically as arrays or binary objects within their systems. Depending on the specific use case, the database might use a traditional relational database management system (RDBMS), a NoSQL database, or even a more specialized vector database designed for handling high-dimensional data efficiently.
Here's a breakdown of how databases might store vectors and what operations they support:
Storage:
-
Arrays: Some databases, such as PostgreSQL, support array data types. A vector can be stored as an array of numbers within a single row. This is straightforward but may not be optimized for high-dimensional vector operations.
-
Binary Objects (BLOBs): Vectors can be serialized into a binary format and stored as a BLOB. This is more storage-efficient, especially for large vectors, but it may require custom code to serialize and deserialize the data.
-
Document Stores: NoSQL databases like MongoDB can store vectors inside document fields. These can be indexed and queried efficiently within the capabilities of the database.
-
Dedicated Vector Databases: There are databases specifically designed for vector storage and operations, such as Milvus, Faiss, and Pinecone. These systems are optimized for similarity search and can handle very high-dimensional data efficiently.
Operations:
-
Insertion: Adding new vectors into the database. This operation involves storing the vector in the appropriate format (array, BLOB, etc.) and updating any necessary indexes.
-
Deletion: Removing vectors from the database. This requires deleting the appropriate records and maintaining index integrity.
-
Update: Modifying existing vectors. This might involve replacing an entire vector or altering specific elements within it.
-
Search/Query: Retrieving vectors based on certain criteria. This could involve exact match queries or range queries in a traditional database, or nearest neighbor searches in databases optimized for vector operations.
-
Similarity Search: Many vector operations involve finding the closest vectors in the database to a given query vector (e.g., cosine similarity, Euclidean distance). Specialized vector databases are particularly good at this operation, often using indexing structures like KD-trees, HNSW (Hierarchical Navigable Small World graphs), or quantization-based methods to speed up the search.
-
Batch Operations: Processing multiple vectors at once, which can include any combination of the above operations. Batch processing is often more efficient than individual record handling.
-
Aggregation: Computing summary statistics or other aggregate information from a set of vectors, such as mean or variance along each dimension.
-
Joins: Combining vector data with other data types or tables, if necessary. This is more common in RDBMS where relational data might be associated with vector data.
In practice, the choice of database and the supported operations will depend heavily on the specific needs of the LLM application, such as the size of the vectors, the number of vectors, the frequency of updates, and the types of queries that need to be supported. Specialized vector databases are generally the preferred choice for applications that rely heavily on efficient similarity search and vector operations at scale.