docs auto-sync

This commit is contained in:
qdrant
2022-12-07 10:38:09 +00:00
parent 468226b8cf
commit 81eee10e60
2 changed files with 188 additions and 2 deletions
@@ -139,6 +139,84 @@ client.update_collection(
This command enables indexing for segments that have more than 10000 vectors stored. This command enables indexing for segments that have more than 10000 vectors stored.
## Collection info
Qdrant allows determining the configuration parameters of an existing collection to better understand how the points are
distributed and indexed.
```http
GET /collections/{collection_name}
{
"result": {
"status": "green",
"optimizer_status": "ok",
"vectors_count": 1068786,
"indexed_vectors_count": 1024232,
"points_count": 1068786,
"segments_count": 31,
"config": {
"params": {
"vectors": {
"size": 384,
"distance": "Cosine"
},
"shard_number": 1,
"replication_factor": 1,
"write_consistency_factor": 1,
"on_disk_payload": false
},
"hnsw_config": {
"m": 16,
"ef_construct": 100,
"full_scan_threshold": 10000,
"max_indexing_threads": 0
},
"optimizer_config": {
"deleted_threshold": 0.2,
"vacuum_min_vector_number": 1000,
"default_segment_number": 0,
"max_segment_size": null,
"memmap_threshold": null,
"indexing_threshold": 20000,
"flush_interval_sec": 5,
"max_optimization_threads": 1
},
"wal_config": {
"wal_capacity_mb": 32,
"wal_segments_ahead": 0
}
},
"payload_schema": {}
},
"status": "ok",
"time": 0.00010143
}
```
```python
client.get_collection(collection_name="{collection_name}")
```
If you insert the vectors into the collection, the `status` field will become `green` once all the points are already processed.
In case the optimization is still running, it will be `yellow`, and might be set to `red` if there were some errors the engine
could not recover from.
There are, however, some other attributes you might be interested in:
- `points_count` - total number of objects (vectors and their payloads) stored in the collection
- `vectors_count` - total number of vectors in a collection. If there are multiple vectors per object, it won't be equal to `points_count`.
- `indexed_vectors_count` - total number of vectors stored in the HNSW index. Qdrant does not store all the vectors in the index, but only if an index segment might be created for a given configuration.
### Indexing vectors in HNSW
In some cases, you might be surprised the value of `indexed_vectors_count` is lower than `vectors_count`. This is an intended behaviour and
depends on the [optimizer configuration](../optimizer). A new index segment is built if the size of non-indexed vectors is higher than the
value of `indexing_threshold`(in KB). If your collection is very small or the dimensionality of the vectors is low, there might be no HNSW segment
created and `indexed_vectors_count` might be equal to `0`.
It is possible to reduce the `indexing_threshold` for an existing collection by [updating collection parameters](#update-collection-parameters).
## Collection aliases ## Collection aliases
In a production environment, it is sometimes necessary to switch different versions of vectors seamlessly. In a production environment, it is sometimes necessary to switch different versions of vectors seamlessly.
@@ -52,6 +52,18 @@ We recommend switching to it if you are already familiar with Qdrant and are try
If you are applying Qdrant for the first time or working on a prototype, you might prefer to use REST. If you are applying Qdrant for the first time or working on a prototype, you might prefer to use REST.
### Clients
Qdrant provides a set of clients for different programming languages. You can find them here:
* [Python](https://github.com/qdrant/qdrant_client) - `pip install qdrant-client`
* [Rust](https://github.com/qdrant/rust-client) - `cargo add qdrant-client`
* [Go](https://github.com/qdrant/go-client) - `go get github.com/qdrant/go-client`
If you are using a language that is not listed here, you can use the REST API directly or generate a client for your language
using [OpenAPI](https://github.com/qdrant/qdrant/blob/master/docs/redoc/master/openapi.json)
or [protobuf](https://github.com/qdrant/qdrant/tree/master/lib/api/src/grpc/proto) definitions.
### Create collection ### Create collection
First - let's create a collection with dot-production metric. First - let's create a collection with dot-production metric.
@@ -67,6 +79,16 @@ curl -X PUT 'http://localhost:6333/collections/test_collection' \
}' }'
``` ```
```python
from qdrant_client import QdrantClient
client = QdrantClient(host="localhost", port=6333)
client.recreate_collection(
collection_name="test_collection",
vectors_config=VectorParams(size=4, distance=Distance.DOT),
)
```
Expected response: Expected response:
```json ```json
@@ -83,6 +105,10 @@ We can ensure that collection was created:
curl 'http://localhost:6333/collections/test_collection' curl 'http://localhost:6333/collections/test_collection'
``` ```
```python
collection_info = client.get_collection(collection_name="test_collection")
```
Expected response: Expected response:
```json ```json
@@ -110,6 +136,13 @@ Expected response:
} }
``` ```
```python
from qdrant_client.http.models import CollectionStatus
assert collection_info.status == CollectionStatus.GREEN
assert collection_info.vectors_count == 0
```
### Add points ### Add points
Let's now add vectors with some payload: Let's now add vectors with some payload:
@@ -129,6 +162,24 @@ curl -L -X PUT 'http://localhost:6333/collections/test_collection/points?wait=tr
}' }'
``` ```
```python
from qdrant_client.http.models import PointStruct
operation_info = client.upsert(
collection_name="test_collection",
wait=True,
points=[
PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}),
PointStruct(id=2, vector=[0.19, 0.81, 0.75, 0.11], payload={"city": ["Berlin", "London"]}),
PointStruct(id=3, vector=[0.36, 0.55, 0.47, 0.94], payload={"city": ["Berlin", "Moscow"]}),
PointStruct(id=4, vector=[0.18, 0.01, 0.85, 0.80], payload={"city": ["London", "Moscow"]}),
PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"count": [0]}),
PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44]),
]
)
```
Expected response: Expected response:
```json ```json
@@ -142,6 +193,12 @@ Expected response:
} }
``` ```
```python
from qdrant_client.http.models import UpdateStatus
assert operation_info.status == UpdateStatus.COMPLETED
```
### Search with filtering ### Search with filtering
Let's start with a basic request: Let's start with a basic request:
@@ -151,10 +208,18 @@ curl -L -X POST 'http://localhost:6333/collections/test_collection/points/search
-H 'Content-Type: application/json' \ -H 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
"vector": [0.2,0.1,0.9,0.7], "vector": [0.2,0.1,0.9,0.7],
"top": 3 "limit": 3
}' }'
``` ```
```python
search_result = client.search(
collection_name="test_collection",
query_vector=[0.2, 0.1, 0.9, 0.7],
limit=3
)
```
Expected response: Expected response:
```json ```json
@@ -169,6 +234,19 @@ Expected response:
} }
``` ```
```python
assert len(search_result) == 3
print(search_result[0])
# ScoredPoint(id=4, score=1.362, ...)
print(search_result[1])
# ScoredPoint(id=1, score=1.273, ...)
print(search_result[2])
# ScoredPoint(id=3, score=1.208, ...)
```
But result is different if we add a filter: But result is different if we add a filter:
```bash ```bash
@@ -186,10 +264,29 @@ curl -L -X POST 'http://localhost:6333/collections/test_collection/points/search
] ]
}, },
"vector": [0.2, 0.1, 0.9, 0.7], "vector": [0.2, 0.1, 0.9, 0.7],
"top": 3 "limit": 3
}' }'
``` ```
```python
from qdrant_client.http.models import Filter, FieldCondition, MatchValue
search_result = client.search(
collection_name="test_collection",
query_vector=[0.2, 0.1, 0.9, 0.7],
query_filter=Filter(
must=[
FieldCondition(
key="city",
match=MatchValue(value="London")
)
]
),
limit=3
)
```
Expected response: Expected response:
```json ```json
@@ -202,3 +299,14 @@ Expected response:
"time": 0.000093972 "time": 0.000093972
} }
``` ```
```python
assert len(search_result) == 2
print(search_result[0])
# ScoredPoint(id=4, score=1.362, ...)
print(search_result[1])
# ScoredPoint(id=2, score=0.871, ...)
```