VectorCollection

class VectorCollection(service_name, name, context)[source]

Bases: Proxy[BlockingVectorCollection]

VectorCollection contains documents with vectors.

Concurrent, distributed, observable and searchable vector collection. The vector collection can work both async(non-blocking) or sync(blocking). Blocking calls return the value of the call and block the execution until return value is calculated. However, async calls return Future and do not block execution. Result of the Future can be used whenever ready. A Future’s result can be obtained with blocking the execution by calling future.result().

The configuration of the vector collection must exist before it can be used.

Example

>>> client.create_vector_collection_config("my_vc", [
>>>    IndexConfig(name="default-vector", metric=Metric.COSINE, dimension=2)
>>> ]
>>> my_vc = client.get_vector_collection("my_vc").blocking()
>>> my_vc.set("key1", Vector("default-vector", Type.DENSE, [0.1, 0.2])
blocking() BlockingVectorCollection[source]

Returns a blocking variant of VectorCollection

get(key: Any) Future[Document | None][source]

Returns the Document for the specified key, or None if this VectorCollection does not contain this key.

Warning

This method returns a clone of the original Document. Modifying the returned Document does not change the actual Document in the VectorCollection. Put the modified Document back to make changes visible to all nodes.

>>> doc = my_vc.get(key)
>>> doc.value.update_some_property()
>>> my_vc.set(key, doc)

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in the key’s class.

Parameters:

key – The specified key.

Returns:

The Document for the specified key or None if there was no mapping for key.

set(key: Any, document: Document) Future[None][source]

Sets a document for the given key in the VectorCollection.

Similar to the put operation except that set doesn’t return the old document, which is more efficient.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters:
  • key – Key of the entry.

  • document – Document of the entry.

put(key: Any, document: Document) Future[Document | None][source]

Associates the specified Document with the specified key in this VectorCollection.

If the VectorCollection previously contained a mapping for the key, the old Document is replaced by the specified Document. If the previous value is not needed, using the set method is more efficient.

Warning

This method returns a clone of the previous Document, not the original (identically equal) Document previously put into the VectorCollection.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in the key’s class.

Parameters:
  • key – Key of the entry.

  • document – Document of the entry.

Returns:

Previous Document associated with the key or None if there was no mapping for the key.

put_all(map: Dict[Any, Document]) Future[None][source]

Copies all the mappings from the specified dictionary to this VectorCollection.

No atomicity guarantees are given. In the case of a failure, some key-document tuples may get written, while others are not.

Parameters:

map – Dictionary which includes mappings to be stored in this VectorCollection.

put_if_absent(key: Any, document: Document) Future[Document | None][source]

Associates the specified key with the given Document if it is not already associated.

Warning

This method returns a clone of the previous Document, not the original (identically equal) Document previously put into the VectorCollection.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in key’s class.

Parameters:
  • key – Key of the entry.

  • document – Document of the entry.

Returns:

Old Document for the given key or None if there is not one.

search_near_vector(vector: Vector, *, include_value: bool = False, include_vectors: bool = False, limit: int = 10, hints: Dict[str, str] = None) Future[List[SearchResult]][source]

Returns the Documents closest to the given vector.

The search is performed using the distance metric set when creating the vector index.

Parameters:
  • vector – The vector to be used as the reference. It must have the same dimension as specified when creating the vector index.

  • include_value – Return value attached to the Document.

  • include_vectors – Return vectors attached to the Document.

  • limit – Limit the maximum number of Documents returned. If not set, 10 is used as the default limit.

Returns:

List of search results.

remove(key: Any) Future[Document | None][source]

Removes the mapping for a key from this VectorCollection if it is present (optional operation).

The VectorCollection will not contain a mapping for the specified key once the call returns.

Warning

This method uses __hash__ and __eq__ methods of binary form of the key, not the actual implementations of __hash__ and __eq__ defined in the key’s class.

Parameters:

key – Key of the mapping to be deleted.

Returns:

The Document associated with key, or None if there was no mapping for key.

delete(key: Any) Future[None][source]

Removes the mapping for a key from this VectorCollection if it is present (optional operation).

Unlike remove(object), this operation does not return the removed Document, which avoids the serialization cost of the returned Document. If the removed Document will not be used, a delete operation is preferred over a remove operation for better performance.

The VectorCollection will not contain a mapping for the specified key once the call returns.

Parameters:

key – Key of the mapping to be deleted.

optimize(index_name: str = None) Future[None][source]

Optimize index by fully removing nodes marked for deletion, trimming neighbor sets to the advertised degree, and updating the entry node as necessary.

Warning

This operation can take a long time to execute and consume a lot of server resources.

Parameters:

index_name – Name of the index to optimize. If not specified, the only index defined for the collection will be used. Must be specified if the collection has more than one index.

clear() Future[None][source]

Clears the VectorCollection.

size() Future[int][source]

Returns the number of Documents in this VectorCollection.

Returns:

Number of Documents in this VectorCollection.