hkulekci / qdrant-php

Qdrant is a vector similarity engine & vector database. It deploys as an API service providing search for the nearest high-dimensional vectors. With Qdrant, embeddings or neural network encoders can be turned into full-fledged applications for matching, searching, recommending, and much more!
MIT License
93 stars 21 forks source link

TypeError encountered in Qdrant\Models\VectorStruct::getName() when the $name attribute is null. #29

Closed tradzero closed 1 year ago

tradzero commented 1 year ago

Summary

TypeError encountered in Qdrant\Models\VectorStruct::getName() when the $name attribute is null.

Description

When an instance of VectorStruct is created with only the $vector argument provided and $name left as null, a TypeError occurs with the following message:

TypeError Qdrant\Models\VectorStruct::getName(): Return value must be of type string, null returned.

The issue seems to arise from the getName() method, which expects to return a string. However, when $name is null, it does not meet this expectation.

The error was resolved by modifying the getName() function to return an empty string when $name is null, like this:

$this->name ? $this->name : '';

Environment

Steps to Reproduce

  1. Create an instance of VectorStruct with only the $vector argument provided, leaving $name as null.
  2. Call the getName() method on this instance.
  3. Observe the TypeError.

Expected Behavior

If the $name argument is not provided when instantiating VectorStruct, calling the getName() method should either not cause a TypeError, or it should be documented that providing a $name is required.

Actual Behavior

A TypeError is thrown when getName() is called on an instance of VectorStruct that was instantiated with $name as null.

Possible Fix

Modify the getName() function to return an empty string when $name is null. This would look like:

$this->name ? $this->name : '';

hkulekci commented 1 year ago

Dear @tradzero, thank you for bringing this to our attention. I have created a pull request to fix the problem, which involves returning null instead of an empty string. It appears that the getName method is used for building search requests and batch operations, as well as the toArray method. I guess, these changes will cover the problem. Could you review the PR?

tradzero commented 1 year ago

@hkulekci it looks good to me, thanks for fix this!