Vectorstore Python API​
Core Classes​
A framework-agnostic interface for interacting with Gel's ext::vectorstore.
This class provides methods for storing, retrieving, and searching vector embeddings. It follows vector database conventions and supports different embedding models.
Args:
-
embedding_model(BaseEmbeddingModel): The embedding model used to generate vectors. -
collection_name(str): The name of the collection. -
record_type(str): The schema type (table name) for storing records. -
client_config(dict | None): The config for the Gel client.
Add multiple items to the vector store in a single transaction. Embeddings will be generated and stored for all items.
Args:
-
items(list[InsertItem]): List of items to add. Each contains:-
text(str): The text content to be embedded -
metadata(dict[str, Any]): Additional data to store
-
Returns:
-
List of database record IDs for the inserted items.
Add pre-computed vector embeddings to the store. Use this method when you have already generated embeddings and want to store them directly without re-computing them.
Args:
-
records(list[InsertRecord]): List of records. Each contains:-
embedding(list[float]): Pre-computed embeddings -
text(Optional[str]): Original text content -
metadata(dict[str, Any]): Additional data to store
-
Returns:
-
List of database record IDs for the inserted items.
Retrieve specific records by their IDs.
Args:
-
ids(list[uuid.UUID]): List of record IDs to retrieve.
Returns:
-
List of retrieved records. Each result contains:
-
id(uuid.UUID): The record's unique identifier -
text(Optional[str]): The original text content -
embedding(Optional[list[float]]): The stored vector embedding -
metadata(Optional[dict[str, Any]]): Any associated metadata
-
Search for similar items in the vector store.
This method:
-
Generates an embedding for the input item
-
Finds records with similar embeddings
-
Optionally filters results based on metadata
-
Returns the most similar items up to the specified limit
Args:
-
item(Any): The query item to find similar matches for. Must be compatible with the embedding model's target_type. -
filters(Optional[CompositeFilter]): Metadata-based filters to use. -
limit(Optional[int]): Max number of results to return. Defaults to 4.
Returns:
-
List of similar items, ordered by similarity. Each result contains:
-
id(uuid.UUID): The record's unique identifier -
text(Optional[str]): The original text content -
embedding(list[float]): The stored vector embedding -
metadata(Optional[dict[str, Any]]): Any associated metadata -
cosine_similarity(float): Similarity score (higher is more similar)
-
Search using a pre-computed vector embedding. Useful when you have already computed the embedding or want to search with a modified/combined embedding vector.
Args:
-
vector(list[float]): The query embedding to search with. Must match the dimensionality of stored embeddings. -
filter_expression(str): Filter expression for metadata filtering. -
limit(Optional[int]): Max number of results to return. Defaults to 4.
Returns:
-
List of similar items, ordered by similarity. Each result contains:
-
id(uuid.UUID): The record's unique identifier -
text(Optional[str]): The original text content -
embedding(list[float]): The stored vector embedding -
metadata(Optional[dict[str, Any]]): Any associated metadata -
cosine_similarity(float): Similarity score (higher is more similar)
-
Update an existing record in the vector store. Only specified fields will be updated. If text is provided but not embedding, a new embedding will be automatically generated.
Args:
-
record(Record):-
id(uuid.UUID): The ID of the record to update -
text(Optional[str]): New text content. If provided without embedding, a new embedding will be generated. -
embedding(Optional[list[float]]): New vector embedding. -
metadata(Optional[dict[str, Any]]): New metadata to store with the record. Completely replaces existing metadata.
-
Returns:
-
The updated record's ID if found and updated, None if no record was found with the given ID.
Raises:
-
ValueError: If no fields are specified for update.
Abstract base class for embedding models.
Any embedding model used with GelVectorstore must implement this
interface. The model is expected to convert input data (text, images, etc.)
into a numerical vector representation.
Convert an input item into a list of floating-point values (vector embedding). Must be implemented in subclasses.
Args:
-
item: Input item to be converted to an embedding
Returns:
-
list[float]: Vector embedding of the input item
Data Classes​
A record retrieved from the vector store, or an update record.
Custom __init__ so we can detect which fields the user passed
(even if they pass None or {}).
Args:
-
id(uuid.UUID): The record's unique identifier -
text(str | None): The text content. Defaults to None. -
embedding(list[float] | None): The vector embedding. Defaults to None. -
metadata(dict[str, Any]): Additional data stored with the record. Defaults to empty dict.
A search result from the vector store.
Inherits from Record
Args:
-
cosine_similarity(float): Similarity score for the search result. Defaults to 0.0.
Metadata Filtering​
Enumeration of supported filter operators for metadata filtering.
Values:
-
EQ: Equal to (=) -
NE: Not equal to (!=) -
GT: Greater than (>) -
LT: Less than (<) -
GTE: Greater than or equal to (>=) -
LTE: Less than or equal to (<=) -
IN: Value in array -
NOT_IN: Value not in array -
LIKE: Pattern matching -
ILIKE: Case-insensitive pattern matching -
ANY: Any array element matches -
ALL: All array elements match -
CONTAINS: String contains value -
EXISTS: Field exists
Represents a single metadata filter condition.
Args:
-
key(str): The metadata field key to filter on -
value(int | float | str): The value to compare against -
operator(FilterOperator): The comparison operator. Defaults to FilterOperator.EQ.
Allows grouping multiple MetadataFilter instances using AND/OR conditions.
Args:
-
filters(list[CompositeFilter|MetadataFilter]): List of filters to combine -
condition(FilterCondition): How to combine the filters. Defaults to FilterCondition.AND.
Get the filter clause for a given CompositeFilter.
Args:
-
filters(CompositeFilter): The composite filter to convert to a clause
Returns:
-
str: The filter clause string for use in queries
Raises:
-
ValueError: If an unknown operator or condition is encountered