Files
qdrant/openapi/tests/openapi_integration/test_nesting_nested_payload_query.py
Arnaud Gourlay 0f0c213c2a Nested object filter (#1602)
* nested object filter

* code review

* add support for must_not in nested

* extract functions

* support and test must_not in SimpleConditionChecker

* add index matching unit test (to be continued)

* remove extra clone

* test with should

* WIP: Nested object filter suggestions (#1855)

* switch to bitvec

* fix clippy

* more tests

* fmt

* fix some tests

* add test with text

* support for nested should

* do not rely on indexes for nested queries & fix test

* use index to make index-aware checks in nested payload

* fix value-count tests

* re-fa-cto-ring

* fmt

---------

Co-authored-by: Arnaud Gourlay <arnaud.gourlay@gmail.com>

---------

Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com>
2023-05-17 11:24:52 +02:00

384 lines
13 KiB
Python

import pytest
from .helpers.helpers import request_with_validation
from .helpers.collection_setup import drop_collection
collection_name = 'test_collection_nesting_nested_payload_query'
def nesting_nested_payload_collection_setup(collection_name, on_disk_payload=False):
response = request_with_validation(
api='/collections/{collection_name}',
method="DELETE",
path_params={'collection_name': collection_name},
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}',
method="PUT",
path_params={'collection_name': collection_name},
body={
"vectors": {
"size": 4,
"distance": "Dot"
},
"on_disk_payload": on_disk_payload
}
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
response = request_with_validation(
api='/collections/{collection_name}/points',
method="PUT",
path_params={'collection_name': collection_name},
query_params={'wait': 'true'},
body={
"points": [
{
"id": 1,
"vector": [0.05, 0.61, 0.76, 0.74],
"payload": {
"arr1": [
{
"arr2": [
{"a": 1, "b": 2}
]
},
{
"arr2": [
{"a": 3, "b": 4},
{"a": 5, "b": 6}
]
}
]
}
},
{
"id": 2,
"vector": [0.15, 0.71, 0.78, 0.24],
"payload": {
"arr1": [
{
"arr2": [
{"a": 2, "b": 3}
]
},
{
"arr2": [
{"a": 3, "b": 5},
{"a": 5, "b": 7}
]
}
]
}
}
]
}
)
assert response.ok
@pytest.fixture(autouse=True)
def setup():
nesting_nested_payload_collection_setup(collection_name=collection_name)
yield
drop_collection(collection_name=collection_name)
def test_nesting_nested_payload_query_operations():
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
# Create nested array index
response = request_with_validation(
api='/collections/{collection_name}/index',
method="PUT",
path_params={'collection_name': collection_name},
query_params={'wait': 'true'},
body={
"field_name": "arr1[].arr2[].a",
"field_schema": "integer"
}
)
assert response.ok
# Validate index creation
response = request_with_validation(
api='/collections/{collection_name}',
method="GET",
path_params={'collection_name': collection_name},
)
assert response.ok
assert response.json()['result']['payload_schema']['arr1[].arr2[].a']['data_type'] == "integer"
assert response.json()['result']['payload_schema']['arr1[].arr2[].a']['points'] == 2
# Search nested field with payload index
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"key": "arr2[].a",
"match": {
"value": 5
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 2
# Search nested field with payload index (negative)
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"key": "arr2[].a",
"match": {
"value": 4
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 0
# Search nested field without payload index
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"key": "arr2[].b",
"match": {
"value": 6
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 1
# Search nested field without payload index (negative)
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1[].arr2",
"filter": {
"must": [
{
"key": "b",
"match": {
"value": 8
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 0
# Search doubly nested field with payload index
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"nested": {
"key": "arr2",
"filter": {
"must": [
{
"key": "a",
"match": {
"value": 5
}
}
]
}
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 2
# Search doubly nested field with and without payload index
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"nested": {
"key": "arr2",
"filter": {
"must": [
{
"key": "a",
"match": {
"value": 5
}
},
{
"key": "b",
"match": {
"value": 6
}
}
]
}
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 1
assert response.json()['result']['points'][0]['id'] == 1
# Search doubly nested field with and without payload index
response = request_with_validation(
api='/collections/{collection_name}/points/scroll',
method="POST",
path_params={'collection_name': collection_name},
body={
"filter": {
"must": [
{
"nested": {
"key": "arr1",
"filter": {
"must": [
{
"nested": {
"key": "arr2",
"filter": {
"should": [
{
"key": "a",
"match": {
"value": 5
}
},
{
"key": "b",
"match": {
"value": 6
}
}
]
}
}
}
]
}
}
}
]
},
"limit": 3
}
)
assert response.ok
assert len(response.json()['result']['points']) == 2