Skip to main content

Class: SqlVectorStore

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:183

SQL-backed vector store implementation.

Uses @framers/sql-storage-adapter for cross-platform persistence. Stores embeddings as JSON blobs and computes similarity in application code (with optional native vector extensions for PostgreSQL).

SqlVectorStore

Implements

Example

const store = new SqlVectorStore();

await store.initialize({
id: 'sql-vector-store',
type: 'sql',
storage: {
filePath: './vectors.db',
priority: ['better-sqlite3', 'sqljs']
},
enableFullTextSearch: true
});

// Create a collection
await store.createCollection('documents', 1536);

// Upsert documents
await store.upsert('documents', [{
id: 'doc-1',
embedding: [...], // 1536-dim vector
textContent: 'Example document content',
metadata: { author: 'Alice', category: 'tech' }
}]);

// Query by similarity
const results = await store.query('documents', queryEmbedding, { topK: 5 });

Implements

Constructors

Constructor

new SqlVectorStore(): SqlVectorStore

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:195

Constructs a SqlVectorStore instance. The store is not operational until initialize() is called.

Returns

SqlVectorStore

Methods

checkHealth()

checkHealth(): Promise<{ details?: any; isHealthy: boolean; }>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:801

Checks the health of the vector store.

Returns

Promise<{ details?: any; isHealthy: boolean; }>

Health status

Implementation of

IVectorStore.checkHealth


collectionExists()

collectionExists(collectionName): Promise<boolean>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:371

Checks if a collection exists.

Parameters

collectionName

string

Collection name to check

Returns

Promise<boolean>

True if collection exists

Implementation of

IVectorStore.collectionExists


createCollection()

createCollection(collectionName, dimension, options?): Promise<void>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:324

Creates a new collection for storing vectors.

Parameters

collectionName

string

Unique name for the collection

dimension

number

Vector embedding dimension

options?

CreateCollectionOptions

Creation options

Returns

Promise<void>

Implementation of

IVectorStore.createCollection


delete()

delete(collectionName, ids?, options?): Promise<DeleteResult>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:727

Deletes documents from a collection.

Parameters

collectionName

string

Collection to delete from

ids?

string[]

Specific document IDs to delete

options?

DeleteOptions

Delete options (filter, deleteAll)

Returns

Promise<DeleteResult>

Deletion result

Implementation of

IVectorStore.delete


deleteCollection()

deleteCollection(collectionName): Promise<void>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:387

Deletes a collection and all its documents.

Parameters

collectionName

string

Collection to delete

Returns

Promise<void>

Implementation of

IVectorStore.deleteCollection


getStats()

getStats(collectionName?): Promise<Record<string, any>>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:856

Gets statistics for a collection or the entire store.

Parameters

collectionName?

string

Specific collection, or all if omitted

Returns

Promise<Record<string, any>>

Statistics

Implementation of

IVectorStore.getStats


hybridSearch()

hybridSearch(collectionName, queryEmbedding, queryText, options?): Promise<QueryResult>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:649

Performs hybrid search combining vector similarity with keyword matching.

Parameters

collectionName

string

Collection to search

queryEmbedding

number[]

Query vector for semantic search

queryText

string

Text query for keyword search

options?

QueryOptions & object

Search options

Returns

Promise<QueryResult>

Combined search results

Example

const results = await store.hybridSearch(
'documents',
queryEmbedding,
'machine learning tutorial',
{ topK: 10, alpha: 0.7 } // 70% vector, 30% keyword
);

initialize()

initialize(config): Promise<void>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:207

Initializes the vector store with the provided configuration.

Creates necessary tables and indexes if they don't exist.

Parameters

config

VectorStoreProviderConfig

Configuration object

Returns

Promise<void>

Throws

If configuration is invalid or initialization fails

Implementation of

IVectorStore.initialize


query()

query(collectionName, queryEmbedding, options?): Promise<QueryResult>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:537

Queries a collection for similar documents.

Parameters

collectionName

string

Collection to query

queryEmbedding

number[]

Query vector

options?

QueryOptions

Query options

Returns

Promise<QueryResult>

Query results sorted by similarity

Implementation of

IVectorStore.query


shutdown()

shutdown(): Promise<void>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:837

Gracefully shuts down the vector store.

Returns

Promise<void>

Implementation of

IVectorStore.shutdown


upsert()

upsert(collectionName, documents, options?): Promise<UpsertResult>

Defined in: packages/agentos/src/rag/implementations/vector_stores/SqlVectorStore.ts:441

Upserts documents into a collection.

Parameters

collectionName

string

Target collection

documents

VectorDocument[]

Documents to upsert

options?

UpsertOptions

Upsert options

Returns

Promise<UpsertResult>

Result of the upsert operation

Implementation of

IVectorStore.upsert