Skip to content

[Store][Demo] Vectorizer->vectorize conditional return type doesn't work #768

@chr-hertel

Description

@chr-hertel

this code in demo:

$search = $io->ask('What do you want to know about?', 'New Symfony Features');
$io->comment(\sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search));
$io->comment('Results are limited to 4 most similar documents.');
$vector = $this->vectorizer->vectorize($search);
$queryResponse = $collection->query(
queryEmbeddings: [$vector->getData()],
nResults: 4,
);

with this return:

* @return Vector|VectorDocument|array<Vector>|array<VectorDocument>
*
* @phpstan-return (
* $values is string|\Stringable ? Vector : (
* $values is EmbeddableDocumentInterface ? VectorDocument : (
* $values is array<string|\Stringable> ? array<Vector> : array<VectorDocument>
* )
* )
* )

leads to:

------ --------------------------------------------------------------------------------------------------------------- 
  Line   src/Blog/Command/QueryCommand.php                                                                              
 ------ --------------------------------------------------------------------------------------------------------------- 
  50     Cannot call method getData() on array<Symfony\AI\Platform\Vector\Vector|Symfony\AI\Store\Document\VectorDocum  
         ent>|Symfony\AI\Platform\Vector\Vector|Symfony\AI\Store\Document\VectorDocument.                               
         🪪  method.nonObject                                                                                           
 ------ --------------------------------------------------------------------------------------------------------------- 

How to reproduce
Reproducible by removing that @phpstan-ignore in that demo class QueryCommand and executing phpstan in demo folder.

Originally posted by @chr-hertel in #760 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't workingDemoIssues & PRs about the demo applicationStatus: Needs ReviewStoreIssues & PRs about the AI Store component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions