CompatibilityOnly available on Node.js.
mysql2 library to create a connection to a SingleStoreDB instance.
Setup
- Establish a SingleStoreDB environment. You have the flexibility to choose between Cloud-based or On-Premise editions.
- Install the mysql2 JS client
npm
Usage
SingleStoreVectorStore manages a connection pool. It is recommended to call await store.end(); before terminating your application to assure all connections are appropriately closed and prevent any possible resource leaks.
Standard usage
npm
SingleStoreVectorStore:
Metadata Filtering
If it is needed to filter results based on specific metadata fields, you can pass a filter parameter to narrow down your search to the documents that match all specified fields in the filter object:Vector indexes
Enhance your search efficiency with SingleStore DB version 8.5 or above by leveraging ANN vector indexes. By settinguseVectorIndex: true during vector store object creation, you can activate this feature.
Additionally, if your vectors differ in dimensionality from the default OpenAI embedding size of 1536, ensure to specify the vectorSize parameter accordingly.
Hybrid search
SingleStoreDB presents a diverse range of search strategies, each meticulously crafted to cater to specific use cases and user preferences. The defaultVECTOR_ONLY strategy utilizes vector operations such as DOT_PRODUCT or EUCLIDEAN_DISTANCE to calculate similarity scores directly between vectors, while TEXT_ONLY employs Lucene-based full-text search, particularly advantageous for text-centric applications.
For users seeking a balanced approach, FILTER_BY_TEXT first refines results based on text similarity before conducting vector comparisons, whereas FILTER_BY_VECTOR prioritizes vector similarity, filtering results before assessing text similarity for optimal matches.
Notably, both FILTER_BY_TEXT and FILTER_BY_VECTOR necessitate a full-text index for operation. Additionally, WEIGHTED_SUM emerges as a sophisticated strategy, calculating the final similarity score by weighing vector and text similarities, albeit exclusively utilizing dot_product distance calculations and also requiring a full-text index.
These versatile strategies empower users to fine-tune searches according to their unique needs, facilitating efficient and precise data retrieval and analysis.
Moreover, SingleStoreDB’s hybrid approaches, exemplified by FILTER_BY_TEXT, FILTER_BY_VECTOR, and WEIGHTED_SUM strategies, seamlessly blend vector and text-based searches to maximize efficiency and accuracy, ensuring users can fully leverage the platform’s capabilities for a wide range of applications.
Related
- Vector store conceptual guide
- Vector store how-to guides