# Qdrant

## Module: [implementation](https://utca.knowledgator.com/framework-structure#implementation).datasources.db

***

***

## <mark style="color:green;">QdrantCreateCollection</mark>

Create empty collection with given parameters. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.** Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], bool]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**:** Name of the collection to create.
  * <mark style="color:red;">**"vectors\_config"**</mark>**:** Configuration of the vector storage.  Vector params contains size and distance for the vector storage. If dict is passed, service will create a vector storage for each key in the dict. If single VectorParams is passed, service will create a single anonymous vector storage.
  * <mark style="color:red;">**"sparse\_vectors\_config"**</mark>**:** Configuration of the sparse vector storage. The service will create a sparse vector storage for each key in the dict.
  * <mark style="color:red;">**"shard\_number"**</mark>**:** Number of shards in collection. Default is 1, minimum is 1.
  * <mark style="color:red;">**"sharding\_method"**</mark>**:** Defines strategy for shard creation. Option auto (default) creates defined number of shards automatically. Data will be distributed between shards automatically. After creation, shards could be additionally replicated, but new shards could not be created. Option custom allows to create shards manually, each shard should be created with assigned unique shard\_key. Data will be distributed between based on shard\_key value.
  * <mark style="color:red;">**"replication\_factor"**</mark>**:** Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode.
  * <mark style="color:red;">**"write\_consistency\_factor"**</mark>**:** Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode.
  * <mark style="color:red;">**"on\_disk\_payload"**</mark>**:** If true - point\`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. \
    \
    Note: those payload values that are involved in filtering and are indexed - remain in RAM.
  * <mark style="color:red;">**"hnsw\_config"**</mark>**:** Params for HNSW index optimizers\_config: Params for optimizer wal\_config: Params for Write-Ahead-Log quantization\_config: Params for quantization, if None - quantization will be disabled init\_from: Use data stored in another collection to initialize this collection timeout: Wait for operation commit timeout in seconds. If timeout is reached - request will return with service error.

#### Returns:

* **bool:** Operation result.

***

***

***

## <mark style="color:green;">QdrantRecreateCollection</mark>

Delete and create empty collection with given parameters. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.**\
Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], bool]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**:** Name of the collection to recreate.
  * <mark style="color:red;">**"vectors\_config"**</mark>**:** Configuration of the vector storage.  Vector params contains size and distance for the vector storage. If dict is passed, service will create a vector storage for each key in the dict. If single VectorParams is passed, service will create a single anonymous vector storage.
  * <mark style="color:red;">**"sparse\_vectors\_config"**</mark>**:** Configuration of the sparse vector storage. The service will create a sparse vector storage for each key in the dict.
  * <mark style="color:red;">**"shard\_number"**</mark>**:** Number of shards in collection. Default is 1, minimum is 1.
  * <mark style="color:red;">**"sharding\_method"**</mark>**:** Defines strategy for shard creation. Option auto (default) creates defined number of shards automatically. Data will be distributed between shards automatically. After creation, shards could be additionally replicated, but new shards could not be created. Option custom allows to create shards manually, each shard should be created with assigned unique shard\_key. Data will be distributed between based on shard\_key value.
  * <mark style="color:red;">**"replication\_factor"**</mark>**:** Replication factor for collection. Default is 1, minimum is 1. Defines how many copies of each shard will be created. Have effect only in distributed mode.
  * <mark style="color:red;">**"write\_consistency\_factor"**</mark>**:** Write consistency factor for collection. Default is 1, minimum is 1. Defines how many replicas should apply the operation for us to consider it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode.
  * <mark style="color:red;">**"on\_disk\_payload"**</mark>**:** If true - point\`s payload will not be stored in memory. It will be read from the disk every time it is requested. This setting saves RAM by (slightly) increasing the response time. \
    \
    Note: those payload values that are involved in filtering and are indexed - remain in RAM.
  * <mark style="color:red;">**"hnsw\_config"**</mark>**:** Params for HNSW index optimizers\_config: Params for optimizer wal\_config: Params for Write-Ahead-Log quantization\_config: Params for quantization, if None - quantization will be disabled init\_from: Use data stored in another collection to initialize this collection timeout: Wait for operation commit timeout in seconds. If timeout is reached - request will return with service error.

#### Returns:

* **bool:** Operation result.

***

***

***

## <mark style="color:green;">QdrantDeleteCollection</mark>

Remove collection and all it's data. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.**\
Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], bool]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**:** Name of the collection to recreate.
  * <mark style="color:red;">**"timeout"**</mark>**:** Wait for operation commit timeout in seconds. If timeout is reached - request will return with service error.
  * <mark style="color:red;">**"kwargs"**</mark>**:** extra parameters.

#### Returns:

* **bool:** Operation result.

***

***

***

## <mark style="color:green;">QdrantAdd</mark>

Adds text documents into qdrant collection. If collection does not exist, it will be created with default parameters. Metadata in combination with documents will be added as payload. Documents will be embedded using the specified embedding model. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.**\
Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], List\[Union\[str, int]]]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**&#x20;(str):** Name of the collection to add documents to.
  * <mark style="color:red;">**"documents"**</mark>**&#x20;(Iterable\[str]):** List of documents to embed and add to the collection.
  * <mark style="color:red;">**"metadata"**</mark>**&#x20;(Iterable\[Dict\[str, Any]], optional):** List of metadata dicts. Defaults to None.
  * <mark style="color:red;">**"ids"**</mark>**&#x20;(Iterable\[models.ExtendedPointId], optional):** List of ids to assign to documents. If not specified, UUIDs will be generated. Defaults to None.
  * <mark style="color:red;">**"batch\_size"**</mark>**&#x20;(int, optional):** How many documents to embed and upload in single request. Defaults to 32.
  * <mark style="color:red;">**"parallel"**</mark>**&#x20;(Optional\[int], optional):** How many parallel workers to use for embedding. Defaults to None. If number is specified, data-parallel process will be used.

#### Returns:

* **List\[Union\[str, int]]:** List of IDs of added documents. If no ids provided, UUIDs will be randomly generated on client side.

***

***

***

## <mark style="color:green;">QdrantUpsert</mark>

Update or insert a new point into the collection. If point with given ID already exists - it will be overwritten. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.** Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], UpdateResult]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**&#x20;(str):** To which collection to insert.
  * <mark style="color:red;">**"points"**</mark>**&#x20;(Point):** Batch or list of points to insert.
  * <mark style="color:red;">**"wait"**</mark>**&#x20;(bool):** Await for the results to be processed.\
    \- If True, result will be returned only when all changes are applied\
    \- If False, result will be returned immediately after the confirmation of receiving.
  * <mark style="color:red;">**"ordering"**</mark>**&#x20;(Optional\[WriteOrdering]):** Define strategy for ordering of the points. Possible values:\
    \- \`weak\` (default) - write operations may be reordered, works faster\
    \- \`medium\` - write operations go through dynamically selected leader, may be inconsistent for a short period of time in case of leader change\
    \- \`strong\` - Write operations go through the permanent leader, consistent, but may be unavailable if leader is down
  * <mark style="color:red;">**"shard\_key\_selector"**</mark>**:** Defines the shard groups that should be used to write updates into. If multiple shard\_keys are provided, the update will be written to each of them.\
    \
    Only works for collections with custom sharding method.

#### Returns:

* **UpdateResult:** Operation result.

***

***

***

## <mark style="color:green;">QdrantDelete</mark>

Update or insert a new point into the collection. If point with given ID already exists - it will be overwritten. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.** Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], UpdateResult]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**&#x20;(str):** To which collection to insert.
  * <mark style="color:red;">**"points\_selector"**</mark>**:** Selects points based on list of IDs or filter. Examples: \
    \- `points=[1, 2, 3, "cd3b53f0-11a7-449f-bc50-d06310e7ed90"]` \
    \- `points=Filter(must=[FieldCondition(key='rand_number', range=Range(gte=0.7))])`
  * <mark style="color:red;">**"wait"**</mark>**&#x20;(bool):** Await for the results to be processed.\
    \- If True, result will be returned only when all changes are applied\
    \- If False, result will be returned immediately after the confirmation of receiving.
  * <mark style="color:red;">**"ordering"**</mark>**&#x20;(Optional\[WriteOrdering]):** Define strategy for ordering of the points. Possible values:\
    \- \`weak\` (default) - write operations may be reordered, works faster\
    \- \`medium\` - write operations go through dynamically selected leader, may be inconsistent for a short period of time in case of leader change\
    \- \`strong\` - Write operations go through the permanent leader, consistent, but may be unavailable if leader is down
  * <mark style="color:red;">**"shard\_key\_selector"**</mark>**:** Defines the shard groups that should be used to write updates into. If multiple shard\_keys are provided, the update will be written to each of them.\
    \
    Only works for collections with custom sharding method.

#### Returns:

* **UpdateResult:** Operation result.

***

***

***

## <mark style="color:green;">QdrantQuery</mark>

Search for documents in a collection. This method automatically embeds the query text using the specified embedding model. If you want to use your own query vector, use search method instead. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.** Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], List\[QueryResponse]]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**:** Collection to search in.
  * <mark style="color:red;">**"query\_text"**</mark>**:** Text to search for. This text will be embedded using the specified embedding model. And then used as a query vector.
  * <mark style="color:red;">**"query\_filter"**</mark>**:** Exclude vectors which doesn't fit given conditions. If None - search among all vectors.
  * <mark style="color:red;">**"limit"**</mark>**:** How many results return.&#x20;
  * <mark style="color:red;">**"kwargs"**</mark>**:** Additional search parameters.

#### Returns:

* **List\[QueryResponse]:** List of scored points.

***

***

***

## <mark style="color:green;">QdrantSearch</mark>

Search for closest vectors in collection taking into account filtering conditions. Subclass of [**Action**](https://utca.knowledgator.com/core/action)**.** Type of [**Action**](https://utca.knowledgator.com/core/action)**\[Dict\[str, Any], List\[ScoredPoint]]**

***

### <mark style="color:blue;">\_\_init\_\_</mark>

#### Arguments:

* <mark style="color:orange;">**client**</mark>**&#x20;(**[**QdrantClient**](https://python-client.qdrant.tech/qdrant_client.qdrant_client)**):** Qdrant client to use
* <mark style="color:orange;">**name**</mark>**&#x20;(Optional\[str], optional):** Name for identification. If equals to None, class name will be used. Defaults to None.
* <mark style="color:orange;">**default\_key**</mark>**&#x20;(str, optional):** Default key used for results that is not of type Dict. Defaults to "output".

***

### <mark style="color:blue;">execute</mark>

#### Arguments:

* <mark style="color:orange;">**input\_data**</mark>**&#x20;(Dict\[str, Any]):**\
  Expected keys:&#x20;
  * <mark style="color:red;">**"collection\_name"**</mark>**:** Collection to search in.
  * <mark style="color:red;">**"query\_vector"**</mark>**:** Search for vectors closest to this. Can be either a vector itself, or a named vector, or a named sparse vector, or a tuple of vector name and vector itself.
  * <mark style="color:red;">**"query\_filter"**</mark>**:** Exclude vectors which doesn't fit given conditions. If None - search among all vectors.
  * <mark style="color:red;">**"search\_params"**</mark>**:** Additional search params.&#x20;
  * <mark style="color:red;">**"limit"**</mark>**:** How many results return.
  * <mark style="color:red;">**"offset"**</mark>**:** Offset of the first result to return. May be used to paginate results. \
    \
    Note: large offset values may cause performance issues.&#x20;
  * <mark style="color:red;">**"with\_payload"**</mark>**:** Specify which stored payload should be attached to the result. If True - attach all payload. If False - do not attach any payload. If List of string - include only specified fields. If PayloadSelector - use explicit rules.
  * <mark style="color:red;">**"with\_vectors"**</mark>**:** If True - Attach stored vector to the search result. If False - Do not attach vector. If List of string - include only specified fields. Defaults to False.
  * <mark style="color:red;">**"score\_threshold"**</mark>**:** Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g. for cosine similarity only higher scores will be returned.&#x20;
  * <mark style="color:red;">**"consistency"**</mark>**:** Read consistency of the search. Defines how many replicas should be queried before returning the result. \
    \
    Values:\
    \- int - number of replicas to query, values should present in all queried replicas\
    \- 'majority' - query all replicas, but return values present in the majority of replicas\
    \- 'quorum' - query the majority of replicas, return values present in all of them\
    \- 'all' - query all replicas, and return values present in all replicas
  * <mark style="color:red;">**"shard\_key\_selector"**</mark>**:** This parameter allows to specify which shards should be queried. If None - query all shards. Only works for collections with custom sharding method.&#x20;
  * <mark style="color:red;">**"timeout"**</mark>**:** Overrides global timeout for this search. Unit is seconds.

#### Returns:

* **List\[ScoredPoint]:** List of found close points with similarity scores.

***

***
