stores/opensearch/README.md
Vector store implementation for OpenSearch using the official @opensearch-project/opensearch SDK
pnpm add @mastra/opensearch
import { OpenSearchVector } from '@mastra/opensearch';
const vectorStore = new OpenSearchVector('http://localhost:9200');
// Create an index
await vectorStore.createIndex({ indexName: 'my-collection', dimension: 1536, metric: 'cosine' });
// Add vectors with documents
const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
const ids = await vectorStore.upsert({ indexName: 'my-collection', vectors, metadata });
// Query vectors with document filtering
const results = await vectorStore.query({
indexName: 'my-collection',
queryVector: [0.1, 0.2, ...],
topK: 10, // topK
filter: { text: { $eq: 'doc1' } }, // metadata filter
includeVector: false, // includeVector
});
Required:
url: URL of your OpenSearch instanceThe following distance metrics are supported:
cosine → Cosine distanceeuclidean → Euclidean distancedotproduct → Dot productcreateIndex({ indexName, dimension, metric? }): Create a new collectionupsert({ indexName, vectors, metadata?, ids? }): Add or update vectorsquery({ indexName, queryVector, topK?, filter?, includeVector? }): Search for similar vectorsupdateVector({ indexName, id?, filter?, update }): Update a single vector by ID or metadata filterdeleteVector({ indexName, id }): Delete a single vector by IDdeleteVectors({ indexName, ids?, filter? }): Delete multiple vectors by IDs or metadata filterlistIndexes(): List all collectionsdescribeIndex(indexName): Get collection statisticsdeleteIndex(indexName): Delete a collection