Skip to main content

Collection

A Collection object for PGVector.
Attributes:
client: The PGVector client.
collection_name (str): The name of the collection. Default is “documents”.
embedding_function (Callable): The embedding function used to generate the vector representation.
Default is None. SentenceTransformer(“all-MiniLM-L6-v2”).encode will be used when None.
Models can be chosen from:
https://huggingface.co/models?library=sentence-transformers metadata (Optional[dict[str, Any]]): The metadata of the collection.
get_or_create (Optional): The flag indicating whether to get or create the collection.
Initialize the Collection object.
Parameters:

Instance Methods

add

Add documents to the collection.
Parameters: Returns:

convert_string_to_array

Convert a string representation of an array to a list of floats.
Parameters:
- array_string (str): The string representation of the array.
Returns:
- list: A list of floats parsed from the input string. If the input is not a string, it returns the input itself.
Parameters: Returns:

cosine_distance

Calculate the cosine distance between two vectors.
Parameters:
- arr1 (List[float]): The first vector.
- arr2 (List[float]): The second vector.
Returns:
- float: The cosine distance between arr1 and arr2.
Parameters: Returns:

count

Get the total number of documents in the collection.
Returns:
int: The total number of documents.
Returns:

create_collection

Create a new collection.
Parameters: Returns:

delete

Delete documents from the collection.
Parameters: Returns:

delete_collection

Delete the entire collection.
Parameters: Returns:

euclidean_distance

Calculate the Euclidean distance between two vectors.
Parameters:
- arr1 (List[float]): The first vector.
- arr2 (List[float]): The second vector.
Returns:
- float: The Euclidean distance between arr1 and arr2.
Parameters: Returns:

get

Retrieve documents from the collection.
Parameters: Returns:

inner_product_distance

Calculate the Euclidean distance between two vectors.
Parameters:
- arr1 (List[float]): The first vector.
- arr2 (List[float]): The second vector.
Returns:
- float: The Euclidean distance between arr1 and arr2.
Parameters: Returns:

modify

Modify metadata for the collection.
Parameters: Returns:

query

Query documents in the collection.
Parameters: Returns:

set_collection_name

Parameters:

table_exists

Check if a table exists in the PostgreSQL database.
Parameters: Returns:

update

Update documents in the collection.
Parameters: Returns:

upsert

Upsert documents into the collection.
Parameters: Returns: