No such prop with name 'title' found in class 'Test' in the schema" when querying Weaviate with near_vector

I’m trying to index and search articles in Weaviate, but I’m encountering an error when querying with near_vector. Here’s my process:

  1. Indexing: I successfully index articles in the “Test” class, with each article having an article_id, title, and body. The vectors are correctly linked based on article_id.
{
  "class_name": "test",
  "data": [
    { "article_id": "0", "title": "title0", "body": "body0" },
    { "article_id": "1", "title": "title1", "body": "body1" },
    ...
  ],
  "vectors": {
    "0": [3.7, 1.4, 4.9, 2.1, 5.6, 7.2, 8.3, 6.5],
    ...
  }
}
  1. Search: When I query with near_vector to retrieve title and distance, I get the following error:
   raise ValueError(f"An error occurred while performing weaviate search : {e}")
ValueError: An error occurred while performing weaviate search : Query call with protocol GRPC search failed with message <AioRpcError of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "no such prop with name 'title' found in class 'Test' in the schema. Check your schema files for which properties in this class are available"
	debug_error_string = "UNKNOWN:Error received from peer  {created_time:"2024-11-08T12:25:18.79653+05:30", grpc_status:2, grpc_message:"no such prop with name \'title\' found in class \'Test\' in the schema. Check your schema files for which properties in this class are available"}"
  1. The indexing appears successful, and I see no issues in the schema setup. Why is this property not accessible in the search query?

Code:

response = weaviate_client.collections.get(weaviate_class_name).query.near_vector(
    near_vector=embedding,
    limit=20,
    return_metadata=MetadataQuery(distance=True),
    return_properties=['title']
)

Any suggestions? Thank you!

hi!!

Can you share a reproducible code?

If possible, with the same code you are using to create the collection, some code similar to what you use to index.

Also, please, always provide the requested information, such as server version, client version, etc.

Thanks!

def batch_upload(
        client: weaviate.WeaviateClient,
        weaviate_class: str,
        content: List[Dict],
        vectors: Dict,
        batch_size: int,
        id_field: str
):
    indexed_article = 0

    collection = client.collections.get(weaviate_class)

    with collection.batch.dynamic() as batch:
        batch.batch_size = batch_size
        for article in content:
            batch.add_object(
                references=article,
                vector=vectors[f"{article[id_field]}"]
            )
            indexed_article += 1

    return indexed_article



def create_index(index_name: str, weaviate_client: weaviate.WeaviateClient):
    try:
        weaviate_client.collections.create(name=index_name)
    except Exception as e:
        raise ValueError(f"An error occurred when creating a weaviate class : {e}")



def check_index_exist(index_name: str, client: weaviate.WeaviateClient) -> bool:
    return client.collections.exists(name=index_name)



def index_data_weaviate(
        weaviate_client: weaviate.WeaviateClient,
        index_name: str,
        content: List[Dict[str, Any]],
        vectors: Dict[str, list[float]],
        id_field: str = 'article_id'
) -> int:
    batch_size = 50
    if check_index_exist(index_name, weaviate_client):
        delete_index(index_name, weaviate_client)

    create_index(index_name, weaviate_client)

    indexed_articles = batch_upload(
        weaviate_client,
        index_name,
        content,
        vectors,
        batch_size,
        id_field
    )
    print(f"Total documents indexed : {indexed_articles}")
    return indexed_articles

I use above code to index the data.
I use index_data_weaviate function for indexing the data.

Also I use following data for indexing:

{
  "class_name": "test",
  "data": [
    {
      "article_id": "0",
      "title": "title0",
      "body": "body0"
    },
    {
      "article_id": "1",
      "title": "title1",
      "body": "body1"
    }
  ],
  "vectors": {
    "0": [3.7, 1.4, 4.9, 2.1, 5.6, 7.2, 8.3, 6.5],
    "1": [8.1, 3.6, 7.0, 0.9, 6.8, 1.3, 4.4, 5.2]
  }
}

Weaviate image version I use is : weaviate:1.25.11,
And weaviate client version is : weaviate-client-4.9.3

Issue is all resolved. I was doing it all incorrectly.

  1. I changed the index creation code. Earlier property data types was not mentioned in my code.
def create_index(index_name: str, weaviate_client: weaviate.WeaviateClient):
    try:
        weaviate_client.collections.create(
            name=index_name,
            vectorizer_config=wvc.config.Configure.Vectorizer.none(),
            properties=[
                wvc.config.Property(name='article_id', data_type=wvc.config.DataType.TEXT),
                wvc.config.Property(name='title', data_type=wvc.config.DataType.TEXT),
                wvc.config.Property(name='body', data_type=wvc.config.DataType.TEXT)
            ]
        )
    except Exception as e:
        raise ValueError(f"An error occurred when creating a weaviate class : {e}")
  1. In the batch upload part I was giving reference to as article, which was incorrect. And In the properties part I am actually passing dictionary with property name and value. Following is the working code:
def batch_upload(
        client: weaviate.WeaviateClient,
        weaviate_class: str,
        content: List[Dict],
        vectors: Dict,
        batch_size: int,
        id_field: str
):
    indexed_article = 0

    collection = client.collections.get(weaviate_class)

    with collection.batch.dynamic() as batch:
        batch.batch_size = batch_size
        for article in content:
            batch.add_object(
                vector=vectors[f"{article[id_field]}"],
                properties={
                    "article_id": article["article_id"],
                    "title": article["title"],
                    "body": article["body"]
                }
            )
            indexed_article += 1

    return indexed_article
  1. And finally the vector search code:
def weaviate_vector_search(
        weaviate_client: weaviate.WeaviateClient,
        weaviate_class_name: str,
        k,
        embedding,
):
    try:
        response = weaviate_client.collections.get(weaviate_class_name).query.near_vector(
            near_vector=embedding,
            limit=20,
            return_metadata=MetadataQuery(distance=True),
            return_properties=['article_id']
        )
    except Exception as e:
        raise ValueError(f"An error occurred while performing weaviate search : {e}")

    for o in response.objects:
        print(o.properties)
        print(o.metadata.distance)

Thanks @ DudaNogueira for your quick attention. We can mark this as resolved.

1 Like

Hi @Sandip !!

Thanks for sharing!

If you have an article id for each object, you may as well use deterministic ids.

Something like:

from weaviate.util import generate_uuid5
            ...
            batch.add_object(
                uuid=generate_uuid5(article["article_id"]),
                vector=vectors[f"{article[id_field]}"],
                properties={
                    "article_id": article["article_id"],
                    "title": article["title"],
                    "body": article["body"]
                }
            )
            ...

Now your batch_upload can be used to both create and update an object :wink:

Happy building!

1 Like