# Empty vector when adding cross references (ref2vec-centroid)

**URL:** <https://forum.weaviate.io/t/empty-vector-when-adding-cross-references-ref2vec-centroid/9564>\
**Category:** Support\
**Tags:** technical\
**Created:** [January 4, 2025, 7:16pm UTC](https://forum.weaviate.io/t/empty-vector-when-adding-cross-references-ref2vec-centroid/9564 "2025-01-04T19:16:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bohdan\_Klishchov](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/bohdan_klishchov/32/3296_2.png) [@Bohdan\_Klishchov](https://forum.weaviate.io/u/Bohdan_Klishchov)\
**Post date:** [January 4, 2025, 7:16pm UTC](https://forum.weaviate.io/t/empty-vector-when-adding-cross-references-ref2vec-centroid/9564/1 "2025-01-04T19:16:58Z")

</div>

My collections:

```await
            "Short",
            properties=[
                Property(
                    name=ShortProps.ID.value,
                    data_type=DataType.INT,
                    description="Unique identifier for the short.",
                    skip_vectorization=True,
                ),
                Property(
                    name=ShortProps.HASH_NAME.value,
                    data_type=DataType.TEXT,
                    description="Unique content hash name for the short.",
                    skip_vectorization=True,
                ),
                Property(
                    name=ShortProps.DESCRIPTION.value,
                    data_type=DataType.TEXT,
                    description="Short description of the content.",
                ),
                Property(
                    name=ShortProps.CATEGORY.value,
                    data_type=DataType.TEXT,
                    description="Category of the short.",
                ),
                Property(
                    name=ShortProps.CONTENT.value,
                    data_type=DataType.BLOB,
                    description="Content of the short (e.g., video, image)."
                ),
            ],
            vectorizer_config=[
                # Set a named vector
                Configure.NamedVectors.multi2vec_bind(
                    name="shorts_vec",
                    text_fields=[
                        Multi2VecField(name=ShortProps.DESCRIPTION.value, weight=0.3),
                        Multi2VecField(name=ShortProps.CATEGORY.value, weight=0.2),
                    ],
                    # video_fields=[
                    # Multi2VecField(name=ShortProps.CONTENT.value, weight=0.5),
                    # ],
                ),
            ],
        )

        await cls.client.collections.create(
            "UserInteractions",
            properties=[
                Property(
                    name=UserInteractionsProps.ID.value,
                    data_type=DataType.INT,
                    description="Unique identifier for the user."
                ),
            ],
            references=[
                ReferenceProperty(
                    name=UserInteractionsProps.LIKED_SHORTS.value,
                    target_collection="Short",
                    description="Short which liked by current user",
                ),
            ],
            vectorizer_config=[
                Configure.NamedVectors.ref2vec_centroid(
                    name="liked_vector",
                    reference_properties=[
                        UserInteractionsProps.LIKED_SHORTS.value,
                    ],
                ),
            ],
        )

```

I tried add cross-references like this:

```auto
async def create_interaction(
        self,
        user_interactions_uuid: UUID,
        short_uuid: UUID,
        interaction_type: InteractionType,
    ) -> None:
        await self.collection.data.reference_add(
            from_uuid=user_interactions_uuid,
            from_property=interaction_type_property[interaction_type.value],
            to=short_uuid
        )

```

but got object with empty vector:

```auto
Object(uuid=_WeaviateUUIDInt('ede63ad5-ae6b-4041-be34-1db9864177c7'), metadata=MetadataReturn(creation_time=None, last_update_time=None, distance=None, certainty=None, score=None, explain_score=None, is_consistent=None, rerank_score=None), properties={'object_id': 2}, references={'liked_shorts': <weaviate.collections.classes.internal._CrossReference object at 0x75f4bf33ae10>}, vector={'liked_vector': []}, collection='UserInteractions')

```

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [January 6, 2025, 2:08pm UTC](https://forum.weaviate.io/t/empty-vector-when-adding-cross-references-ref2vec-centroid/9564/2 "2025-01-06T14:08:34Z")

</div>

hi @Bohdan_Klishchov !!

Welcome to our community 🤗

Can you share a full running code? This has proven more efficient to discover this kind of issue as sometimes the issue is on underlying code that is not share 😬

Here we have a set of recipes here, that can serve as base for this:

> **[GitHub - weaviate/recipes: This repository shares end-to-end notebooks on how...](https://github.com/weaviate/recipes)**
>
> This repository shares end-to-end notebooks on how to use various Weaviate features and integrations!

I have searched, and there isn’t a recipe for ref2vec-centroid 😬

Maybe we can create one 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![Bohdan\_Klishchov](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/bohdan_klishchov/32/3296_2.png) [@Bohdan\_Klishchov](https://forum.weaviate.io/u/Bohdan_Klishchov)\
**Post date:** [January 6, 2025, 3:31pm UTC](https://forum.weaviate.io/t/empty-vector-when-adding-cross-references-ref2vec-centroid/9564/3 "2025-01-06T15:31:26Z")

</div>

hello @DudaNogueira  
I simplified my code:

```import
import asyncio

import weaviate
from weaviate.classes.config import Configure
from weaviate.client import WeaviateAsyncClient
from weaviate.collections.classes.grpc import QueryReference
from weaviate.collections.classes.config_vectorizers import Multi2VecField
from weaviate.collections.classes.config import Property, DataType, ReferenceProperty

from core.settings import get_settings

settings = get_settings()

async def init_collections(client: WeaviateAsyncClient):

    if await client.collections.exists('Short'):
        return
    if await client.collections.exists('UserInteractions'):
        return
    await client.collections.create(
        "Short",
        properties=[
            Property(
                name='object_id',
                data_type=DataType.INT,
                description="Unique identifier for the short.",
                skip_vectorization=True,
            ),
            Property(
                name='description',
                data_type=DataType.TEXT,
                description="Short description of the content.",
            ),
            Property(
                name='category',
                data_type=DataType.TEXT,
                description="Category of the short.",
            ),
        ],
        vectorizer_config=[
            # Set a named vector
            Configure.NamedVectors.multi2vec_bind(
                name="shorts_vec",
                text_fields=[
                    Multi2VecField(name='description', weight=0.6),
                    Multi2VecField(name='category', weight=0.4),
                ]
            ),
        ],
    )

    await client.collections.create(
        "UserInteractions",
        properties=[
            Property(
                name='object_id',
                data_type=DataType.INT,
                description="Unique identifier for the user."
            ),
        ],
        references=[
            ReferenceProperty(
                name='liked_shorts',
                target_collection="Short",
                description="Short which liked by current user",
            ),
        ],
        vectorizer_config=Configure.Vectorizer.ref2vec_centroid(
            reference_properties=[
                'liked_shorts'
            ]
        ),
    )

async def main():
    client: WeaviateAsyncClient = weaviate.use_async_with_local(
        host=settings.WEAVIATE_HOST,
        port=settings.WEAVIATE_PORT,
        skip_init_checks=True
    )
    await client.connect()
    try:
        await init_collections(client=client)

        short_collection = client.collections.get('Short')
        user_collection = client.collections.get('UserInteractions')

        short_uuid = await short_collection.data.insert(properties={
            'object_id': 1,
            'description': 'description1',
            'category': 'category1'
        }, uuid=uuid.uuid4())
        print(f'created short: {short_uuid}')

        user_uuid = await user_collection.data.insert(properties={'object_id': 1}, uuid=uuid.uuid4())
        print(f'created user: {user_uuid}')

        # creating cross-reference
        await user_collection.data.reference_add(
            from_uuid=user_uuid,
            from_property='liked_shorts',
            to=short_uuid
        )

        resp = await user_collection.query.fetch_object_by_id(
            uuid=user_uuid,
            include_vector=True,
            return_references=QueryReference(
                link_on='liked_shorts',
                return_properties=["object_id"],
            ),
        )

        print(resp)

    finally:
        await client.close()

if __name__ == ' __main__':
    asyncio.run(main())

```

got this output:

```auto
created short: 09e06d77-a1f6-4274-b0ae-485f532322fd
created user: 0c6ff736-ef4a-45e9-9e34-93ff67a53dfe
ObjectSingleReturn(uuid=_WeaviateUUIDInt('0c6ff736-ef4a-45e9-9e34-93ff67a53dfe'), metadata=MetadataSingleObjectReturn(creation_time=datetime.datetime(2025, 1, 6, 15, 20, 12, 837000, tzinfo=datetime.timezone.utc), last_update_time=datetime.datetime(2025, 1, 6, 15, 20, 12, 840000, tzinfo=datetime.timezone.utc), is_consistent=None), properties={'object_id': 1}, references={'liked_shorts': <weaviate.collections.classes.internal._CrossReference object at 0x7c28da11e610>}, vector={}, collection='UserInteractions')

```

i use python 3.11 and weaviate-client 4.9.6  
for me asynchronicity is important, so I can’t downgrade to the old 3rd client, where it is not supported, even if there are more examples  
thank you for your reply

p.s. I’m working on a recommendation system
