SingleStore is a robust, high-performance distributed SQL database solution designed to excel in both cloud and on-premises environments. Boasting a versatile feature set, it offers seamless deployment options while delivering unparalleled performance.A standout feature of SingleStore is its advanced support for vector storage and operations, making it an ideal choice for applications requiring intricate AI capabilities such as text similarity matching. With built-in vector functions like dot_product and euclidean_distance, SingleStore empowers developers to implement sophisticated algorithms efficiently. For developers keen on leveraging vector data within SingleStore, a comprehensive tutorial is available, guiding them through the intricacies of working with vector data. This tutorial delves into the Vector Store within SingleStoreDB, showcasing its ability to facilitate searches based on vector similarity. Leveraging vector indexes, queries can be executed with remarkable speed, enabling swift retrieval of relevant data. Moreover, SingleStore’s Vector Store seamlessly integrates with full-text indexing based on Lucene, enabling powerful text similarity searches. Users can filter search results based on selected fields of document metadata objects, enhancing query precision. What sets SingleStore apart is its ability to combine vector and full-text searches in various ways, offering flexibility and versatility. Whether prefiltering by text or vector similarity and selecting the most relevant data, or employing a weighted sum approach to compute a final similarity score, developers have multiple options at their disposal. In essence, SingleStore provides a comprehensive solution for managing and querying vector data, offering unparalleled performance and flexibility for AI-driven applications.
Class | Package | JS support |
---|---|---|
SingleStoreVectorStore | langchain_singlestore | ✅ |
For the langchain-community version
SingleStoreDB
(deprecated), seethe v0.2 documentation.Setup
To access SingleStore vector stores you’ll need to install thelangchain-singlestore
integration package.
%pip install -qU “langchain-singlestore”
Initialization
To initializeSingleStoreVectorStore
, you need an Embeddings
object and connection parameters for the SingleStore database.
Required Parameters
- embedding (
Embeddings
): A text embedding model.
Optional Parameters
-
distance_strategy (
DistanceStrategy
): Strategy for calculating vector distances. Defaults toDOT_PRODUCT
. Options:DOT_PRODUCT
: Computes the scalar product of two vectors.EUCLIDEAN_DISTANCE
: Computes the Euclidean distance between two vectors.
-
table_name (
str
): Name of the table. Defaults toembeddings
. -
content_field (
str
): Field for storing content. Defaults tocontent
. -
metadata_field (
str
): Field for storing metadata. Defaults tometadata
. -
vector_field (
str
): Field for storing vectors. Defaults tovector
. -
id_field (
str
): Field for storing IDs. Defaults toid
. -
use_vector_index (
bool
): Enables vector indexing (requires SingleStore 8.5+). Defaults toFalse
. -
vector_index_name (
str
): Name of the vector index. Ignored ifuse_vector_index
isFalse
. -
vector_index_options (
dict
): Options for the vector index. Ignored ifuse_vector_index
isFalse
. -
vector_size (
int
): Size of the vector. Required ifuse_vector_index
isTrue
. -
use_full_text_search (
bool
): Enables full-text indexing on content. Defaults toFalse
.
Connection Pool Parameters
- pool_size (
int
): Number of active connections in the pool. Defaults to5
. - max_overflow (
int
): Maximum connections beyondpool_size
. Defaults to10
. - timeout (
float
): Connection timeout in seconds. Defaults to30
.
Database Connection Parameters
- host (
str
): Hostname, IP, or URL for the database. - user (
str
): Database username. - password (
str
): Database password. - port (
int
): Database port. Defaults to3306
. - database (
str
): Database name.
Additional Options
- pure_python (
bool
): Enables pure Python mode. - local_infile (
bool
): Allows local file uploads. - charset (
str
): Character set for string values. - ssl_key, ssl_cert, ssl_ca (
str
): Paths to SSL files. - ssl_disabled (
bool
): Disables SSL. - ssl_verify_cert (
bool
): Verifies server’s certificate. - ssl_verify_identity (
bool
): Verifies server’s identity. - autocommit (
bool
): Enables autocommits. - results_type (
str
): Structure of query results (e.g.,tuples
,dicts
).
Manage vector store
TheSingleStoreVectorStore
assumes that a Document’s ID is an integer. Below are examples of how to manage the vector store.
Add items to vector store
You can add documents to the vector store as follows:Update items in vector store
To update an existing document in the vector store, use the following code:Delete items from vector store
To delete documents from the vector store, use the following code:Query vector store
Once your vector store has been created and the relevant documents have been added you will most likely wish to query it during the running of your chain or agent.Query directly
Performing a simple similarity search can be done as follows:- TODO: Edit and then run code cell to generate output
Metadata filtering
SingleStoreDB elevates search capabilities by enabling users to enhance and refine search results through prefiltering based on metadata fields. This functionality empowers developers and data analysts to fine-tune queries, ensuring that search results are precisely tailored to their requirements. By filtering search results using specific metadata attributes, users can narrow down the scope of their queries, focusing only on relevant data subsets.Vector index
Enhance your search efficiency with SingleStore DB version 8.5 or above by leveraging ANN vector indexes. By settinguse_vector_index=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 vector_size
parameter accordingly.
Search strategies
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.