Skip to content

Commit

Permalink
add scroll api
Browse files Browse the repository at this point in the history
  • Loading branch information
generall committed Jun 20, 2021
1 parent d0e837e commit 489fbef
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "qdrant_client"
version = "0.3.3"
version = "0.3.4"
description = "Client library for the Qdrant vector search engine"
authors = ["Andrey Vasnetsov <[email protected]>"]
packages = [
Expand Down
60 changes: 54 additions & 6 deletions qdrant_openapi_client/api/points_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,35 @@ def _build_for_recommend_points(
body = jsonable_encoder(recommend_request)

return self.api_client.request(
type_=m.InlineResponse2006,
type_=m.InlineResponse2007,
method="POST",
url="/collections/{name}/points/recommend",
path_params=path_params,
json=body,
)

def _build_for_scroll_points(
self,
name: str,
scroll_request: m.ScrollRequest = None,
):
"""
Scroll request - paginate over all points which matches given condition
"""
path_params = {
"name": str(name),
}

body = jsonable_encoder(scroll_request)

return self.api_client.request(
type_=m.InlineResponse2006,
method="POST",
url="/collections/{name}/points/scroll",
path_params=path_params,
json=body,
)

def _build_for_search_points(
self,
name: str,
Expand All @@ -219,7 +241,7 @@ def _build_for_search_points(
body = jsonable_encoder(search_request)

return self.api_client.request(
type_=m.InlineResponse2006,
type_=m.InlineResponse2007,
method="POST",
url="/collections/{name}/points/search",
path_params=path_params,
Expand Down Expand Up @@ -277,17 +299,30 @@ async def recommend_points(
self,
name: str,
recommend_request: m.RecommendRequest = None,
) -> m.InlineResponse2006:
) -> m.InlineResponse2007:
return await self._build_for_recommend_points(
name=name,
recommend_request=recommend_request,
)

async def scroll_points(
self,
name: str,
scroll_request: m.ScrollRequest = None,
) -> m.InlineResponse2006:
"""
Scroll request - paginate over all points which matches given condition
"""
return await self._build_for_scroll_points(
name=name,
scroll_request=scroll_request,
)

async def search_points(
self,
name: str,
search_request: m.SearchRequest = None,
) -> m.InlineResponse2006:
) -> m.InlineResponse2007:
return await self._build_for_search_points(
name=name,
search_request=search_request,
Expand Down Expand Up @@ -331,17 +366,30 @@ def recommend_points(
self,
name: str,
recommend_request: m.RecommendRequest = None,
) -> m.InlineResponse2006:
) -> m.InlineResponse2007:
return self._build_for_recommend_points(
name=name,
recommend_request=recommend_request,
)

def scroll_points(
self,
name: str,
scroll_request: m.ScrollRequest = None,
) -> m.InlineResponse2006:
"""
Scroll request - paginate over all points which matches given condition
"""
return self._build_for_scroll_points(
name=name,
scroll_request=scroll_request,
)

def search_points(
self,
name: str,
search_request: m.SearchRequest = None,
) -> m.InlineResponse2006:
) -> m.InlineResponse2007:
return self._build_for_search_points(
name=name,
search_request=search_request,
Expand Down
2 changes: 1 addition & 1 deletion qdrant_openapi_client/docs/InlineResponse2006.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**time** | **float** | Time spent to process this request | [optional]
**status** | **str** | | [optional] if omitted the server will use the default value of "ok"
**result** | [**[ScoredPoint]**](ScoredPoint.md) | | [optional]
**result** | [**ScrollResult**](ScrollResult.md) | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
12 changes: 12 additions & 0 deletions qdrant_openapi_client/docs/InlineResponse2007.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# InlineResponse2007

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**time** | **float** | Time spent to process this request | [optional]
**status** | **str** | | [optional] if omitted the server will use the default value of "ok"
**result** | [**[ScoredPoint]**](ScoredPoint.md) | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


94 changes: 89 additions & 5 deletions qdrant_openapi_client/docs/PointsApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Method | HTTP request | Description
[**get_point**](PointsApi.md#get_point) | **GET** /collections/{name}/points/{id} | Retrieve point by id
[**get_points**](PointsApi.md#get_points) | **POST** /collections/{name}/points | Retrieve points by ids
[**recommend_points**](PointsApi.md#recommend_points) | **POST** /collections/{name}/points/recommend | Recommend points
[**scroll_points**](PointsApi.md#scroll_points) | **POST** /collections/{name}/points/scroll | Scroll points
[**search_points**](PointsApi.md#search_points) | **POST** /collections/{name}/points/search | Search points
[**update_points**](PointsApi.md#update_points) | **POST** /collections/{name} | Update points (vectors, payloads, indexes) in collection

Expand Down Expand Up @@ -156,7 +157,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **recommend_points**
> InlineResponse2006 recommend_points(name)
> InlineResponse2007 recommend_points(name)
Recommend points

Expand All @@ -167,7 +168,7 @@ import time
import qdrant_openapi_client
from qdrant_openapi_client.api import points_api
from qdrant_openapi_client.model.recommend_request import RecommendRequest
from qdrant_openapi_client.model.inline_response2006 import InlineResponse2006
from qdrant_openapi_client.model.inline_response2007 import InlineResponse2007
from qdrant_openapi_client.model.error_response import ErrorResponse
from pprint import pprint
# Defining the host is optional and defaults to http://localhost:6333
Expand Down Expand Up @@ -221,6 +222,89 @@ Name | Type | Description | Notes

### Return type

[**InlineResponse2007**](InlineResponse2007.md)

### Authorization

No authorization required

### HTTP request headers

- **Content-Type**: application/json
- **Accept**: application/json

### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**200** | successful operation | - |
**0** | error | - |

[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **scroll_points**
> InlineResponse2006 scroll_points(name)
Scroll points

Scroll request - paginate over all points which matches given condition

### Example

```python
import time
import qdrant_openapi_client
from qdrant_openapi_client.api import points_api
from qdrant_openapi_client.model.inline_response2006 import InlineResponse2006
from qdrant_openapi_client.model.scroll_request import ScrollRequest
from qdrant_openapi_client.model.error_response import ErrorResponse
from pprint import pprint
# Defining the host is optional and defaults to http://localhost:6333
# See configuration.py for a list of all supported configuration parameters.
configuration = qdrant_openapi_client.Configuration(
host = "http://localhost:6333"
)


# Enter a context with an instance of the API client
with qdrant_openapi_client.ApiClient() as api_client:
# Create an instance of the API class
api_instance = points_api.PointsApi(api_client)
name = "name_example" # str | Name of the collection to retrieve from
scroll_request = ScrollRequest(
filter=,
limit=0,
offset=0,
with_payload=True,
with_vector=True,
) # ScrollRequest | Pagination and filter parameters (optional)

# example passing only required values which don't have defaults set
try:
# Scroll points
api_response = api_instance.scroll_points(name)
pprint(api_response)
except qdrant_openapi_client.ApiException as e:
print("Exception when calling PointsApi->scroll_points: %s\n" % e)

# example passing only required values which don't have defaults set
# and optional values
try:
# Scroll points
api_response = api_instance.scroll_points(name, scroll_request=scroll_request)
pprint(api_response)
except qdrant_openapi_client.ApiException as e:
print("Exception when calling PointsApi->scroll_points: %s\n" % e)
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**name** | **str**| Name of the collection to retrieve from |
**scroll_request** | [**ScrollRequest**](ScrollRequest.md)| Pagination and filter parameters | [optional]

### Return type

[**InlineResponse2006**](InlineResponse2006.md)

### Authorization
Expand All @@ -241,7 +325,7 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

# **search_points**
> InlineResponse2006 search_points(name)
> InlineResponse2007 search_points(name)
Search points

Expand All @@ -251,7 +335,7 @@ Search points
import time
import qdrant_openapi_client
from qdrant_openapi_client.api import points_api
from qdrant_openapi_client.model.inline_response2006 import InlineResponse2006
from qdrant_openapi_client.model.inline_response2007 import InlineResponse2007
from qdrant_openapi_client.model.search_request import SearchRequest
from qdrant_openapi_client.model.error_response import ErrorResponse
from pprint import pprint
Expand Down Expand Up @@ -303,7 +387,7 @@ Name | Type | Description | Notes

### Return type

[**InlineResponse2006**](InlineResponse2006.md)
[**InlineResponse2007**](InlineResponse2007.md)

### Authorization

Expand Down
15 changes: 15 additions & 0 deletions qdrant_openapi_client/docs/ScrollRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ScrollRequest

Scroll request - paginate over all points which matches given condition
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**filter** | **object** | Look only for points which satisfies this conditions. If not provided - all points. | [optional]
**limit** | **int, none_type** | Page size. Default: 10 | [optional]
**offset** | **int, none_type** | Start ID to read points from. Default: 0 | [optional]
**with_payload** | **bool, none_type** | Return point payload with the result. Default: true | [optional]
**with_vector** | **bool, none_type** | Return point vector with the result. Default: false | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


12 changes: 12 additions & 0 deletions qdrant_openapi_client/docs/ScrollResult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ScrollResult

Result of the points read request. Contains
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**points** | [**[Record]**](Record.md) | List of retrieved points |
**next_page_offset** | **int, none_type** | Offset which should be used to retrieve a next page result | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


2 changes: 1 addition & 1 deletion qdrant_openapi_client/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
API description for Qdrant vector search engine. This document describes CRUD and search operations on collections of points (vectors with payload). Qdrant supports any combinations of `should`, `must` and `must_not` conditions, which makes it possible to use in applications when object could not be described solely by vector. It could be location features, availability flags, and other custom properties businesses should take into account. ## Examples This examples cover the most basic use-cases - collection creation and basic vector search. ### Create collection First - let's create a collection with dot-production metric. ``` curl -X POST 'http://localhost:6333/collections' \\ -H 'Content-Type: application/json' \\ --data-raw '{ \"create_collection\": { \"name\": \"test_collection\", \"vector_size\": 4, \"distance\": \"Dot\" } }' ``` Expected response: ``` { \"result\": true, \"status\": \"ok\", \"time\": 0.031095451 } ``` We can ensure that collection was created: ``` curl 'http://localhost:6333/collections/test_collection' ``` Expected response: ``` { \"result\": { \"status\": \"green\", \"vectors_count\": 0, \"segments_count\": 5, \"disk_data_size\": 0, \"ram_data_size\": 0, \"config\": { \"params\": { \"vector_size\": 4, \"distance\": \"Dot\" }, \"hnsw_config\": { \"m\": 16, \"ef_construct\": 100, \"full_scan_threshold\": 10000 }, \"optimizer_config\": { \"deleted_threshold\": 0.2, \"vacuum_min_vector_number\": 1000, \"max_segment_number\": 5, \"memmap_threshold\": 50000, \"indexing_threshold\": 20000, \"payload_indexing_threshold\": 10000, \"flush_interval_sec\": 1 }, \"wal_config\": { \"wal_capacity_mb\": 32, \"wal_segments_ahead\": 0 } } }, \"status\": \"ok\", \"time\": 2.1199e-05 } ``` ### Add points Let's now add vectors with some payload: ``` curl -L -X POST 'http://localhost:6333/collections/test_collection?wait=true' \\ -H 'Content-Type: application/json' \\ --data-raw '{ \"upsert_points\": { \"points\": [ {\"id\": 1, \"vector\": [0.05, 0.61, 0.76, 0.74], \"payload\": {\"city\": {\"type\": \"keyword\", \"value\": \"Berlin\"}}}, {\"id\": 2, \"vector\": [0.19, 0.81, 0.75, 0.11], \"payload\": {\"city\": {\"type\": \"keyword\", \"value\": [\"Berlin\", \"London\"] }}}, {\"id\": 3, \"vector\": [0.36, 0.55, 0.47, 0.94], \"payload\": {\"city\": {\"type\": \"keyword\", \"value\": [\"Berlin\", \"Moscow\"] }}}, {\"id\": 4, \"vector\": [0.18, 0.01, 0.85, 0.80], \"payload\": {\"city\": {\"type\": \"keyword\", \"value\": [\"London\", \"Moscow\"]}}}, {\"id\": 5, \"vector\": [0.24, 0.18, 0.22, 0.44], \"payload\": {\"count\": {\"type\": \"integer\", \"value\": [0]}}}, {\"id\": 6, \"vector\": [0.35, 0.08, 0.11, 0.44]} ] } }' ``` Expected response: ``` { \"result\": { \"operation_id\": 0, \"status\": \"completed\" }, \"status\": \"ok\", \"time\": 0.000206061 } ``` ### Search with filtering Let's start with a basic request: ``` curl -L -X POST 'http://localhost:6333/collections/test_collection/points/search' \\ -H 'Content-Type: application/json' \\ --data-raw '{ \"vector\": [0.2,0.1,0.9,0.7], \"top\": 3 }' ``` Expected response: ``` { \"result\": [ { \"id\": 4, \"score\": 1.362 }, { \"id\": 1, \"score\": 1.273 }, { \"id\": 3, \"score\": 1.208 } ], \"status\": \"ok\", \"time\": 0.000055785 } ``` But result is different if we add a filter: ``` curl -L -X POST 'http://localhost:6333/collections/test_collection/points/search' \\ -H 'Content-Type: application/json' \\ --data-raw '{ \"filter\": { \"should\": [ { \"key\": \"city\", \"match\": { \"keyword\": \"London\" } } ] }, \"vector\": [0.2, 0.1, 0.9, 0.7], \"top\": 3 }' ``` Expected response: ``` { \"result\": [ { \"id\": 4, \"score\": 1.362 }, { \"id\": 2, \"score\": 0.871 } ], \"status\": \"ok\", \"time\": 0.000093972 } ``` # noqa: E501
The version of the OpenAPI document: 0.3.2
The version of the OpenAPI document: 0.3.4
Contact: [email protected]
Generated by: https://openapi-generator.tech
"""
Expand Down
41 changes: 34 additions & 7 deletions qdrant_openapi_client/models/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from enum import Enum
from typing import Any, Dict, List, Optional, Union

try:
from typing import Literal
except ImportError:
# Python 3.7 backport
from typing_extensions import Literal
from typing import Any, Dict, List, Literal, Optional, Union

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -237,6 +231,14 @@ class InlineResponse2005(BaseModel):


class InlineResponse2006(BaseModel):
time: Optional[float] = Field(None, description="Time spent to process this request")
status: Literal[
"ok",
] = Field(None, description="")
result: Optional["ScrollResult"] = Field(None, description="")


class InlineResponse2007(BaseModel):
time: Optional[float] = Field(None, description="Time spent to process this request")
status: Literal[
"ok",
Expand Down Expand Up @@ -517,6 +519,31 @@ class ScoredPoint(BaseModel):
score: float = Field(..., description="Points vector distance to the query vector")


class ScrollRequest(BaseModel):
"""
Scroll request - paginate over all points which matches given condition
"""

filter: Optional["Filter"] = Field(
None, description="Look only for points which satisfies this conditions. If not provided - all points."
)
limit: Optional[int] = Field(None, description="Page size. Default: 10")
offset: Optional[int] = Field(None, description="Start ID to read points from. Default: 0")
with_payload: Optional[bool] = Field(None, description="Return point payload with the result. Default: true")
with_vector: Optional[bool] = Field(None, description="Return point vector with the result. Default: false")


class ScrollResult(BaseModel):
"""
Result of the points read request. Contains
"""

next_page_offset: Optional[int] = Field(
None, description="Offset which should be used to retrieve a next page result"
)
points: List["Record"] = Field(..., description="List of retrieved points")


class SearchParams(BaseModel):
"""
Additional parameters of the search
Expand Down

0 comments on commit 489fbef

Please sign in to comment.