VectorStore

org.llm4s.vectorstore.VectorStore
trait VectorStore

Low-level vector storage abstraction for RAG and semantic search.

VectorStore provides a backend-agnostic interface for storing and searching vector embeddings. Implementations can be SQLite, pgvector, Qdrant, Milvus, Pinecone, or any other vector database.

This is the foundation layer - higher-level abstractions like MemoryStore can build on top of VectorStore for domain-specific functionality.

Key design principles:

  • Backend-agnostic: Same interface for all vector databases
  • Minimal API: Focus on core vector operations
  • Composable: Can be wrapped with additional functionality
  • Type-safe: Uses Result[A] for error handling

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def clear(): Result[Unit]

Clear all records from the store.

Clear all records from the store.

Attributes

Returns

Success or error

def close(): Unit

Close the store and release resources.

Close the store and release resources.

Attributes

def count(filter: Option[MetadataFilter]): Result[Long]

Count total records in the store.

Count total records in the store.

Value parameters

filter

Optional metadata filter

Attributes

Returns

Record count

def delete(id: String): Result[Unit]

Delete a record by its ID.

Delete a record by its ID.

Value parameters

id

The record identifier

Attributes

Returns

Success or error

def deleteBatch(ids: Seq[String]): Result[Unit]

Delete multiple records by their IDs.

Delete multiple records by their IDs.

Value parameters

ids

The record identifiers

Attributes

Returns

Success or error

def deleteByFilter(filter: MetadataFilter): Result[Long]

Delete all records matching a metadata filter.

Delete all records matching a metadata filter.

Value parameters

filter

The metadata filter

Attributes

Returns

Number of records deleted

def deleteByPrefix(prefix: String): Result[Long]

Delete all records with IDs starting with the given prefix.

Delete all records with IDs starting with the given prefix.

Value parameters

prefix

The ID prefix to match

Attributes

Returns

Number of records deleted

def get(id: String): Result[Option[VectorRecord]]

Retrieve a record by its ID.

Retrieve a record by its ID.

Value parameters

id

The record identifier

Attributes

Returns

The record if found

def getBatch(ids: Seq[String]): Result[Seq[VectorRecord]]

Retrieve multiple records by their IDs.

Retrieve multiple records by their IDs.

Value parameters

ids

The record identifiers

Attributes

Returns

The found records (missing IDs are silently skipped)

def list(limit: Int, offset: Int, filter: Option[MetadataFilter]): Result[Seq[VectorRecord]]

List records with pagination.

List records with pagination.

Value parameters

filter

Optional metadata filter

limit

Maximum records to return

offset

Number of records to skip

Attributes

Returns

Records in insertion order

def search(queryVector: Array[Float], topK: Int, filter: Option[MetadataFilter]): Result[Seq[ScoredRecord]]

Search for similar vectors using cosine similarity.

Search for similar vectors using cosine similarity.

Value parameters

filter

Optional metadata filter

queryVector

The query embedding

topK

Number of results to return

Attributes

Returns

Matching records with similarity scores

Get statistics about the vector store.

Get statistics about the vector store.

Attributes

Returns

Store statistics

def upsert(record: VectorRecord): Result[Unit]

Store a vector record.

Store a vector record.

If a record with the same ID exists, it will be replaced.

Value parameters

record

The record to store

Attributes

Returns

Success or error

def upsertBatch(records: Seq[VectorRecord]): Result[Unit]

Store multiple vector records in a batch.

Store multiple vector records in a batch.

More efficient than individual upserts for bulk operations.

Value parameters

records

The records to store

Attributes

Returns

Success or error