Usage of _ReferencePropertyMultiTarget vs list[ReferenceProperty]?

Description

python client v4

eg I have a Document class, and I want references to:

  • project
  • client
  • task

A doc can link to a single project, and a single client, but multiple tasks.

Questions:

  1. is the usage of list[ReferenceProperty] correct?
  2. what’s the difference between list[ReferenceProperty] and _ReferencePropertyMultiTarget? (in other words when to use _ReferencePropertyMultiTarget?)
  3. when I filter by the referenced task’s properties, and there are multiple tasks linked, will it return docs as long as at least 1 task fulfills the filter criteria? (any vs all)
documents.query.fetch_objects(
                return_properties=["heading", "content"],
                filters=Filter.by_ref(link_on="task")
                .by_property("task_type")
                .equal("creative"),
            )

simplified schema defined below:

client.collections.create(
        name=DOC_NAME,
        description="Document",
        inverted_index_config=Configure.inverted_index(
            index_null_state=True,
            index_property_length=True,
        ),
        multi_tenancy_config=Configure.multi_tenancy(True),
            Property(
                name="title",
                data_type=DataType.TEXT,
                description="Document title",
            ),
            Property(
                name="content",
                data_type=DataType.TEXT,
                description="Content of the document",
            )
        ],
        references=[
            ReferenceProperty(name="project", target_collection=PROJECT_NAME),
            ReferenceProperty(name="client", target_collection=CLIENT_NAME),
            ReferenceProperty(name="task", target_collection=TASK_NAME),
        ],
    )

Server Setup Information

  • Weaviate Server Version: latest
  • Deployment Method: cloud
  • Multi Node? Number of Running Nodes: 1
  • Client Language and Version: eng, latest

Yes, looks all corect.

in other words when to use _ReferencePropertyMultiTarget?)

When your reference is to more than one other collection. Then you can do

    from_collection.config.add_reference(
        ReferenceProperty.MultiTarget(
            name="ref", target_collections=[CLIENT_NAME, TASK_NAME]
        )
    )

Thanks for the reply Dirk,

So is that a shorthand for a list of two references

[
            ReferenceProperty(name="ref", target_collection=CLIENT_NAME),
            ReferenceProperty(name="ref", target_collection=TASK_NAME),
]

or is it functionally different?

btw if you know of a video / docs explaining the usage difference, would also appreciate :smiley:

There is a functional difference between the two:

ReferenceProperty(name="ref", target_collection=CLIENT_NAME)

Creates a reference-property ref that will always point to objects of collection client.

ReferenceProperty.MultiTarget(
            name="ref", target_collections=[CLIENT_NAME, TASK_NAME]
        )

Creates a reference-property ref that will point to objects of either collection client OR Task.

btw if you know of a video / docs explaining the usage difference, would also appreciate

Multi-target is not really mention in the docs. In general I’d try to stick with single-target references