SurrealStorage
BaseVectorStorage using SurrealDB,
a scalable, distributed database with WebSocket support, for
efficient vector storage and similarity search.
SurrealDB official site and documentation can be found at:
SurrealDB <https://surrealdb.com>_
Parameters:
- url (str): WebSocket URL for connecting to SurrealDB (default: “ws://localhost:8000/rpc”).
- table (str): Name of the table used for storing vectors (default: “vector_store”).
- vector_dim (int): Dimensionality of the stored vectors.
- distance (VectorDistance): Distance metric used for similarity comparisons (default: VectorDistance.COSINE).
- namespace (str): SurrealDB namespace to use (default: “default”). (default:
"default") - database (str): SurrealDB database name (default: “demo”). (default:
"demo") - user (str): Username for authentication (default: “root”). (default:
"root") - password (str): Password for authentication (default: “root”). (default:
"root")
- SurrealDB supports flexible schema and powerful querying capabilities via SQL-like syntax over WebSocket.
- This implementation manages connection setup and ensures the target table exists.
- Suitable for applications requiring distributed vector storage and search with real-time updates.
init
- url (str): WebSocket URL for connecting to SurrealDB. (default: :obj:
"ws://localhost:8000/rpc") - table (str): Name of the table used for vector storage. (default: :obj:
"vector_store") - vector_dim (int): Dimensionality of the stored vectors. (default: :obj:
786) - distance (VectorDistance): Distance metric for similarity searches. (default: :obj:
VectorDistance.COSINE) - namespace (str): SurrealDB namespace to use. (default: :obj:
"default") - database (str): SurrealDB database name. (default: :obj:
"demo") - user (str): Username for authentication. (default: :obj:
"root") - password (str): Password for authentication. (default: :obj:
"root")
_table_exists
_get_table_info
_create_table
_drop_table
_check_and_create_table
_validate_and_convert_records
- records (List[VectorRecord]): List of vector records to insert.
query
- query (VectorDBQuery): Query containing the query vector and top_k value.
add
- records (List[VectorRecord]): List of vector records to add.
delete
- ids (Optional[List[str]]): List of record IDs to delete.
- if_all (bool): Whether to delete all records in the table.