# \[Non deterministic vector search return\]

**URL:** <https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840>\
**Category:** Support\
**Created:** [March 28, 2024, 6:09pm UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840 "2024-03-28T18:09:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fairymane](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/fairymane/32/1029_2.png) [@fairymane](https://forum.weaviate.io/u/fairymane)\
**Post date:** [March 28, 2024, 6:09pm UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840/1 "2024-03-28T18:09:44Z")

</div>

Hi Team, we observed the vector similarity search return results varies for the same query on different attempts, want to get some clarity on whether it is an expected behavior of Weaviate?

Below is a sample query we use, the embedding\_id should be unique as it was used to create the uuid when importing the data (generate\_uuid5(embedding\_id)).  
The collection has ~17M embeddings, out of 1000 results returned in two attemps, ~10 -15 embedding\_ids are different.

> query = f"“”  
> {{  
> Get {{  
> Data\_discovery\_test (  
> limit: 1000  
> nearVector: {{  
> vector: [{query\_vector}]  
> }}
> 
> ```
> ) {{
> embedding_id
> _additional {{
> distance
> }}
> }}
> }}
> }}
> """
> 
> ```
> 
> response = weaviate\_client.query.raw(query)

\*note the collection has replica factor : 2  
Here is the corresponding replicationConfig/shardingConfig:

```auto
   'replicationConfig': {'factor': 2},
   'shardingConfig': {'virtualPerPhysical': 128,
    'desiredCount': 2,
    'actualCount': 2,
    'desiredVirtualCount': 256,
    'actualVirtualCount': 256,
    'key': '_id',
    'strategy': 'hash',
    'function': 'murmur3'},

```

An other potential query issue I found (maybe have some correlation with above issue) is conditional filter on some unique Id returns multiple results, e,g,

```auto
INPUT_EMBEDDING_ID = "***"
query = '{Get {
          Data_discovery(
            where: {
              path: ["embedding_id"] 
              operator: Equal 
              valueText: {INPUT_EMBEDDING_ID}
              } 
            )
            {
              embedding_id 
              _additional {vector}
            }
          }
        }' 

response = weaviate_client.query.raw(query)

```

# Response returns 5 different embeddings / embedding IDs for a unique input embedding\_id.

But if filter on the id of the collection, (the id is generated with generate\_uuid5(embedding\_id) at data import phase) the return result is unique  
from weaviate.util import generate\_uuid5

```auto
INPUT_EMBEDDING_ID = "***"
UUID = generate_uuid5(INPUT_EMBEDDING_ID)
query = '{Get {
          Data_discovery(
            where: {
              path: ["_id"] 
              operator: Equal 
              valueText: {UUID}
              } 
            )
            {
              embedding_id 
              _additional {vector}
            }
          }
        }' 
response = weaviate_client.query.raw(query)

```

The data collection is the same as the above query, which contains ~17M embedding

### Server Setup Information

- Weaviate Server Version: 1.24.3/helm chart 16.8.7
- Deployment Method: helm chart / K8s
- Multi Node? Number of Running Nodes: 2
- Client Language and Version: Python 3.10 / weaviate-client 4.5.1

---

<div class="post-metadata">

**Author:** ![fairymane](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/fairymane/32/1029_2.png) [@fairymane](https://forum.weaviate.io/u/fairymane)\
**Post date:** [April 2, 2024, 4:46pm UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840/2 "2024-04-02T16:46:13Z")

</div>

Hello @DudaNogueira , hope this can get some attention from you.

---

<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:** [April 5, 2024, 7:19pm UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840/3 "2024-04-05T19:19:16Z")

</div>

Hi @fairymane ! Sorry for the delay gere ☹

I was out those days.

This seems a case where there are multiple objects with the same `embedding_id` property with value of `INPUT_EMBEDDING_ID`

You can check this by querying something like:

```auto
{Get {
          Data_discovery(
            where: {
              path: ["embedding_id"] 
              operator: Equal 
              valueText: {INPUT_EMBEDDING_ID}
              } 
            )
            {
              embedding_id 
              _additional {vector id}
            }
          }
        }

```

note that I added the id to be returned on that query.

You should get the N amount of object, with different ids.

Let me know if this helps 🙂

---

<div class="post-metadata">

**Author:** ![fairymane](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/fairymane/32/1029_2.png) [@fairymane](https://forum.weaviate.io/u/fairymane)\
**Post date:** [April 9, 2024, 12:42am UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840/4 "2024-04-09T00:42:47Z")

</div>

Hi @DudaNogueira , no problem, hope you have some good time-off!

Here I asked 2 questions, the first one is about the non- deterministic return results on the same query, do you have any idea on why it happened? Is the non deterministic return results expected or unexpected behavior ? (The weaviate cluster has 3 nodes, and the collection replica is 2).

For the second question, with you suggestion, here is the data returned:

```auto
INPUT_EMBEDDING_ID = "2024.02.09.00.38.40_KMHKC81EFR1000069 __CAM_M_L1__ 1707443135521304__left_1_top_1_width_938_height_618"

    query = f"""
        {{
            Get {{
                Data_discovery (
                     where: {{
                        path: ["embedding_id"],
                        operator: Equal,
                        valueText: "{INPUT_EMBEDDING_ID}"
                      }}
      
                ) {{
                    embedding_id
                    _additional 
                    {{
                      id
                    }}
                }}
            }}
        }}
        """
response = weaviate_client.query.raw(query)

```

Here is the returns:

> {‘\_additional’: {‘id’: ‘26624310-b690-57fc-a8f3-94d791333105’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_1877\_top\_1\_width\_938\_height\_618’},  
> {‘\_additional’: {‘id’: ‘3d27d492-17fe-555e-b32d-a27c663b8f21’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_1\_top\_1\_width\_938\_height\_618’},  
> {‘\_additional’: {‘id’: ‘4cef39ee-ca26-5764-abcb-e9ae6f193b0e’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_1\_top\_619\_width\_938\_height\_618’},  
> {‘\_additional’: {‘id’: ‘58c2b127-d6a2-5369-a575-e7fc2b7194ed’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_1\_top\_1237\_width\_938\_height\_618’},  
> {‘\_additional’: {‘id’: ‘a9cd538c-922f-5529-9cfb-99ecdda84090’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_939\_top\_1\_width\_938\_height\_618’}]

You can see 5 different embedding\_ids above, and only the second item in the returned results above actually matches the INPUT\_EMBEDDING\_ID, and the rest are different embedding\_ids (they share some prefix though: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_\*’).

The collection was imported with explicitly generated uuid:

```auto
...
            batch.add_data_object(
                data_object=pilotImage.get_properties(),
                class_name=PilotImage.name(collection_name),
                vector=pilotImage.embeddings,
                **uuid = generate_uuid5(pilotImage.embedding_id)**
            )
...

```

So in my case if I filter on the id of the collection, (the id is generated with generate\_uuid5(embedding\_id) at data import phase) the return result is unique:

```auto
GEN_UUID = generate_uuid5(INPUT_EMBEDDING_ID)
print(GEN_UUID)

```

> 3d27d492-17fe-555e-b32d-a27c663b8f21

```auto
query_2 = f"""
        {{
            Get {{
                Data_discovery (
                     where: {{
                        path: ["_id"],
                        operator: Equal,
                        valueText: "{GEN_UUID}"
                      }}
      
                ) {{
                    embedding_id
                    _additional 
                    {{
                      id
                    }}
                }}
            }}
        }}
        """
response_2 = weaviate_client.query.raw(query_2)
print(response_2)

```

> [{‘\_additional’: {‘id’: ‘3d27d492-17fe-555e-b32d-a27c663b8f21’}, ‘embedding\_id’: ‘2024.02.09.00.38.40\_KMHKC81EFR1000069\_\_CAM\_M\_L1\_\_1707443135521304\_\_left\_1\_top\_1\_width\_938\_height\_618’}]

So it seems the inverted index on the embedding\_id doesn’t perform the filtering properly.

---

<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:** [April 12, 2024, 2:46pm UTC](https://forum.weaviate.io/t/non-deterministic-vector-search-return/1840/5 "2024-04-12T14:46:25Z")

</div>

When doing a filter, you need to be aware of the tokenization:

> **[Collection schema | Weaviate - Vector Database](https://weaviate.io/developers/weaviate/config-refs/schema#tokenization)**
>
> Introduction

so `2024.02.09.00.38.40_KMHKC81EFR1000069 __CAM_M_L1__ 1707443135521304__left_1_top_1_width_938_height_618` will be tokenized into multiple small parts.

If you don’t want that, you need to set the tokenization for that property to `field`

For the second question, when you search

```auto
where: {{
                        path: ["_id"],
                        operator: Equal,
                        valueText: "3d27d492-17fe-555e-b32d-a27c663b8f21"
                      }}

```

you should get only one result, with the id 3d27d492-17fe-555e-b32d-a27c663b8f21.

Are you getting more results? Sorry, I am a bit confused here 🙂

It’s always interesting to post full working example, preferably a python notebook, so I can easily follow along.

Thanks!
