Giter VIP home page Giter VIP logo

Comments (7)

generall avatar generall commented on July 23, 2024 1

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.

hwk06023 avatar hwk06023 commented on July 23, 2024

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.

generall avatar generall commented on July 23, 2024

You can use should instead of must, which is equivalent of the "OR" condition

from qdrant.

hwk06023 avatar hwk06023 commented on July 23, 2024

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.

hwk06023 avatar hwk06023 commented on July 23, 2024

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.

generall avatar generall commented on July 23, 2024

You can try to use is_empty condition instead of has_key

from qdrant.

hwk06023 avatar hwk06023 commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.