[Python API feedback] Cross-reference properties

Hi Weaviate community - we are looking for your feedback on some experimental changes to the Python API.

One area is how we fetch cross-referenced properties. What do you think about this proposal?

from weaviate import LinkTo

result = (
    client.query.get("Article", [
        "title", "url", "wordCount",
        LinkTo(link_on="inPublication", linked_class="Publication", properties=["name"])
    ])
)

This would replace:

result = (
    client.query.get("Article", [
        "title", "url", "wordCount", 
        "inPublication {... on Publication {name}}"
    ])
)

We would love to get your thoughts on the idea, and the specific syntax. Let us know in the thread!

You can test it out with the latest version of the Python client, and on this server:

client = weaviate.Client(
    url="https://edu-demo.weaviate.network",
    auth_client_secret=weaviate.AuthApiKey(api_key="learn-weaviate"),
)
3 Likes

Looks good to me – much more precise and will hopefully get type hints. How would it look if we wanted to fetch the reference but not resolve it?

Hi @gabriel - I’m not sure what you mean by this.

Are you looking for some sort a way of lazily loading the cross-reference data so that you don’t have to fetch the name property, for example?

Yes that would be it – also if I want to group per reference id on the client side …

ie

Get all the books (which and an Author ref) and then group books by author in my app. I don’t need to resolve the reference to then get _additional.id the reference beacon would suffice.

Could you give an GQL example on how that would look like?

Hmm. So @gabriel do you mean like this, using the old syntax?

result = (
    client.query.get("Article", [
        "title", "url", "wordCount",
        "inPublication {... on Publication {_additional {id} }}"
    ]).with_limit(3).do()
)

@jphwang yeah that’s it but without having to resolve the underlying object. Can we just get the reference data?