Comments (7)
Would it be equivalent to something like:
(has_key(A) AND (A-datetime condition)) OR (not has_key(A) and (B-datetime condition)) ?
from qdrant.
Yesss. Let me explain it a little more accurately.
All data have "modified-datetime(B-datetime condition)" and some data have "expired-datetime(A-datetime condition)".
# (B-datetime condition)
modified_datetime_range = {
"key": "modified_datetime",
"range": {
"gte": past_time_range.isoformat(), # past_time_range = now_time - relativedelta(months=10)
"lt": now_time.isoformat(),
},
}
# (A-datetime condition)
expired_datetime = {
"key": "expired_datetime",
"range": {"gte": now_time.isoformat()}
In this environment, how should I write the conditions when searching as follows?
results = client.search(
collection_name=collection_name,
query_vector=query_vector,
query_filter=models.Filter(
must=[] # How can such conditions fit in here?
),
limit=top_k,
score_threshold=threshold
)
from qdrant.
You can use should
instead of must
, which is equivalent of the "OR" condition
from qdrant.
Thank you for guiding me so kindly!
And, I just learned about 'Nested object filter' through a link, HERE.
Now, I think I can use conditional clauses that include all the nesting.
I'm grateful for this great open source.
from qdrant.
Sorry, I just have one more question.
Following your advice, I implemented it this way. However, it seems there is no part that checks for the existence of the key. How can I apply that?
A_filter = models.Filter(
must=[
models.Filter(has_key="expiration_date"),
models.FieldCondition(
key=expiration_date.get("key"),
range=models.DatetimeRange(
gt=expiration_date.get("gt"),
gte=expiration_date.get("gte"),
lt=expiration_date.get("lt"),
lte=expiration_date.get("lte"),
),
),
]
)
B_filter = models.Filter(
must_not=[models.Filter(has_key="expiration_date")],
must=[
models.FieldCondition(
key=expiration_date.get("key"),
range=models.DatetimeRange(
gt=datetime_values.get("gt"),
gte=datetime_values.get("gte"),
lt=datetime_values.get("lt"),
lte=datetime_values.get("lte"),
),
)
],
)
should_list.append(A_filter)
should_list.append(B_filter)
# In search
query_filter=models.Filter(should=should_list)
I would appreciate it if you could assume that these have each been applied with index
.
from qdrant.
You can try to use is_empty
condition instead of has_key
from qdrant.
I resolved it using the method you described. Thank you!
for datetime in datetime_list:
datetime_key = datetime.get("key")
datetime_range = datetime.get("range", {})
if datetime_key == mustkey:
filter_tmp = models.Filter(
must_not=[
models.IsEmptyCondition(
is_empty=models.PayloadField(key=mustkey)
),
],
must=[
models.FieldCondition(
key=datetime_key,
range=models.DatetimeRange(
gt=datetime_range.get("gt"),
gte=datetime_range.get("gte"),
lt=datetime_range.get("lt"),
lte=datetime_range.get("lte"),
),
),
],
)
else:
filter_tmp = models.Filter(
must=[
models.IsEmptyCondition(
is_empty=models.PayloadField(key=mustkey)
),
models.FieldCondition(
key=datetime_key,
range=models.DatetimeRange(
gt=datetime_range.get("gt"),
gte=datetime_range.get("gte"),
lt=datetime_range.get("lt"),
lte=datetime_range.get("lte"),
),
),
]
)
date_should_list.append(filter_tmp)
# in search, must=must_list
must_list.append(models.Filter(should=date_should_list))
https://qdrant.tech/documentation/concepts/filtering/#is-empty
Mentioning the existence of keys in the payload might be helpful to someone.
I've resolved it thanks to your help, and I think I'll be able to use qdrant more useful in the future.
Thank you. 🙌
from qdrant.
Related Issues (20)
- Update with strong/medium ordering might try to deactivate last active shard HOT 1
- Relevance score exceeds 1 HOT 2
- Shifting already created collections from in memory to disk HOT 4
- Add details to the collection overview
- Score NaN for zeroed uint8 vectors HOT 1
- Transport error on self hosted 3 node cluster HOT 10
- Filtering: Support for Subset Matching in Array Fields HOT 4
- ERROR qdrant::startup: Panic occurred hs.commit 64 is out of range [0, 0], raft_id: 548108420710242
- Out Of Memory with on_disk = true HOT 3
- Upload speed limitation for snapshot ship to AWS s3?
- Prefix all metrics with `qdrant_` following best-practices
- Some metrics (like `cluster_enabled`) are wrongly typed as COUNTER instead of GAUGE // `_total` postfix only to be used for counters
- S3 snapshots storage feature: missing endpoint_url parameter in documentation, credentials not picked up from env vars HOT 1
- Building image with Dockerfile failed. HOT 1
- s3 snapshots storage feature: errors when used with GCS S3 interface
- Flaky test `segment_builder_test::test_building_new_segment`
- Provide a Grafana dashboad for cluster status, request and performance metrics
- Flaky test `filtrable_hnsw_test::test_filterable_hnsw::case_1_nearest`
- Charabia update broke `test_multilingual_tokenizer_chinese`
- webui:Page not found HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qdrant.