Giter Club home page Giter Club logo

Comments (2)

shadowlinyf avatar shadowlinyf commented on May 28, 2024

I have a more thorough example of the problem and I now think it is related to use combined filter on reference
here is the link of the post on weaviate support forum.
https://forum.weaviate.io/t/combined-filter-on-reference-has-unexpect-behaviour/1683

the code to reproduce the problem

import weaviate
from weaviate.collections.classes.config import Property, DataType, ReferenceProperty
from weaviate.collections.classes.filters import Filter
from weaviate.collections.classes.grpc import QueryReference

from base_dependencies import load_config

client = weaviate.connect_to_custom(
    http_host=load_config("weaviate")["host"],
    http_port=load_config("weaviate")["http_port"],
    http_secure=False,
    grpc_host="localhost",
    grpc_port=load_config("weaviate")["grpc_port"],
    grpc_secure=False,
    auth_credentials=weaviate.auth.AuthApiKey(api_key=load_config("weaviate")["api_key"])
)

client.collections.delete(["a", "b", ])
b = client.collections.create(
    "b",
    properties=[
        Property(name="text", data_type=DataType.TEXT),
        Property(name="code", data_type=DataType.TEXT),
    ],
)
a = client.collections.create(
    name="a", references=[ReferenceProperty(name="has_b", target_collection=b.name)]
)

b1 = b.data.insert(properties={"text": "text1", "code": "1752871214070435840321"})
b2 = b.data.insert(properties={"text": "text2", "code": "1752871214070435840521"})
b3 = b.data.insert(properties={"text": "text3", "code": "1752871214070435840621"})
b4 = b.data.insert(properties={"text": "text4", "code": "1752871214070435840721"})

a1 = a.data.insert({}, references={"has_b": [b1, b2]})
a2 = a.data.insert({}, references={"has_b": [b3, b4]})

a_objects = a.query.fetch_objects(
    filters=Filter.by_ref("has_b").by_property("code").greater_or_equal("1752871214070435840326")
            & Filter.by_ref("has_b").by_property("code").less_or_equal("1752871214070435840327"),
    return_references=[
        QueryReference(
            link_on="has_b",
            return_properties=["code"]
        )
    ]
).objects
# should be no object returned, because no code is between 1752871214070435840326 and 1752871214070435840327
print("record count:", len(a_objects))
for a_object in a_objects:
    print("------")
    print("a_object_uuid:", a_object.uuid)
    for ref in a_object.references["has_b"].objects:
        print(ref.properties["code"])
    print("------")
# but it returns 1 objects
# the object has two has_b reference code="1752871214070435840321" and "1752871214070435840521"


# if we use the same filter on b collection, it returns 0 objects.work as expected
b_objects = b.query.fetch_objects(
    filters=Filter.by_property("code").greater_or_equal("1752871214070435840326")
            & Filter.by_property("code").less_or_equal("1752871214070435840327"),
).objects

print("============================================")
print("record count:", len(b_objects))
for b_object in b_objects:
    print(b_object)

client.close()

from weaviate.

shadowlinyf avatar shadowlinyf commented on May 28, 2024

I found it is my mistake.closed

from weaviate.

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.