Skip to main content

VectorRecord

class VectorRecord(BaseModel):
Encapsulates information about a vector’s unique identifier and its payload, which is primarily used as a data transfer object when saving to vector storage. Parameters:
  • vector (List[float]): The numerical representation of the vector.
  • id (str, optional): A unique identifier for the vector. If not provided, an random uuid will be assigned.
  • payload (Optional[Dict[str, Any]], optional): Any additional metadata or information related to the vector. (default: :obj:None)

VectorDBQuery

class VectorDBQuery(BaseModel):
Represents a query to a vector database. Parameters:
  • query_vector (List[float]): The numerical representation of the query vector.
  • top_k (int, optional): The number of top similar vectors to retrieve from the database. (default: :obj:1)

init

def __init__(
    self,
    query_vector: List[float],
    top_k: int,
    **kwargs: Any
):
Pass in query_vector and tok_k as positional arg. Parameters:
  • query_vector (List[float]): The numerical representation of the query vector.
  • top_k (int, optional): The number of top similar vectors to retrieve from the database. (default: :obj:1)

VectorDBQueryResult

class VectorDBQueryResult(BaseModel):
Encapsulates the result of a query against a vector database. Parameters:
  • record (VectorRecord): The target vector record.
  • similarity (float): The similarity score between the query vector and the record.

create

def create(
    cls,
    similarity: float,
    vector: List[float],
    id: str,
    payload: Optional[Dict[str, Any]] = None
):
A class method to construct a VectorDBQueryResult instance.

VectorDBStatus

class VectorDBStatus(BaseModel):
Vector database status. Parameters:
  • vector_dim (int): The dimension of stored vectors.
  • vector_count (int): The number of stored vectors.

BaseVectorStorage

class BaseVectorStorage(ABC):
An abstract base class for vector storage systems.

add

def add(self, records: List[VectorRecord], **kwargs: Any):
Saves a list of vector records to the storage. Parameters:
  • records (List[VectorRecord]): List of vector records to be saved. **kwargs (Any): Additional keyword arguments.

delete

def delete(self, ids: List[str], **kwargs: Any):
Deletes a list of vectors identified by their IDs from the storage. Parameters:
  • ids (List[str]): List of unique identifiers for the vectors to be deleted. **kwargs (Any): Additional keyword arguments.

status

def status(self):
Returns: VectorDBStatus: The vector database status.

query

def query(self, query: VectorDBQuery, **kwargs: Any):
Searches for similar vectors in the storage based on the provided query. Parameters:
  • query (VectorDBQuery): The query object containing the search vector and the number of top similar vectors to retrieve. **kwargs (Any): Additional keyword arguments.
Returns: List[VectorDBQueryResult]: A list of vectors retrieved from the storage based on similarity to the query vector.

clear

def clear(self):
Remove all vectors from the storage.

load

def load(self):
Load the collection hosted on cloud service.

client

def client(self):
Provides access to the underlying vector database client.

get_payloads_by_vector

def get_payloads_by_vector(self, vector: List[float], top_k: int):
Returns payloads of top k vector records that closest to the given vector. This function is a wrapper of BaseVectorStorage.query. Parameters:
  • vector (List[float]): The search vector.
  • top_k (int): The number of top similar vectors.
Returns: List[List[Dict[str, Any]]]: A list of vector payloads retrieved from the storage based on similarity to the query vector.