Closed jtomek closed 4 months ago
But why not centralize the logic? Each Vector Operator has an name, operator string, description, compatibility (e.g. Hamming and Jaccard work with binary vectors), etc.
To future-proof the package and make it flexible, it would be nice to centralize this logic. Moreover, in my particular case, I find myself needing to generate othe pgvector queries with dynamic operators and use the following:
/**
* @see https://github.com/pgvector/pgvector-php/pull/12
*/
protected function tempGetDistanceOperator(): string
{
return match ($this->distance) {
Distance::L2 => '<->',
Distance::InnerProduct => '<#>',
Distance::Cosine => '<=>',
Distance::L1 => '<+>',
Distance::Hamming => '<~>',
Distance::Jaccard => '<%>',
default => throw new \InvalidArgumentException('Invalid distance')
};
}
which fits, in my view, into the enum.
Thank you for considering my comment.
P.S. This is my first ever pull request. :)
Hi @jtomek, thanks for the PR, but this doesn't seem like a common need.