-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from gregpriday/feature/multiple-vector-support
Multiple Vector Support
- Loading branch information
Showing
16 changed files
with
415 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ vendor/ | |
.phpunit.result.cache | ||
.phpunit.cache | ||
coverage | ||
/qdrant_storage | ||
/composer.lock | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Qdrant\Models; | ||
|
||
use Qdrant\Exception\InvalidArgumentException; | ||
|
||
class MultiVectorStruct implements VectorStructInterface | ||
{ | ||
protected array $vectors = []; | ||
|
||
public function __construct(array $vectors = []) | ||
{ | ||
foreach ($vectors as $name => $vector) { | ||
$this->addVector($name, $vector); | ||
} | ||
} | ||
|
||
public function addVector(string $name, array $vector): void | ||
{ | ||
$this->vectors[$name] = $vector; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
if(empty($this->vectors)) { | ||
throw new InvalidArgumentException("No vectors added yet"); | ||
} | ||
|
||
return array_key_first($this->vectors); | ||
} | ||
|
||
public function toSearchArray(string $name = null): array | ||
{ | ||
// Throw an error if no name is given | ||
if ($name === null) { | ||
throw new InvalidArgumentException("Must provide a name to search"); | ||
} | ||
|
||
if(!isset($this->vectors[$name])) { | ||
throw new InvalidArgumentException("Vector with name $name not found"); | ||
} | ||
|
||
return [ | ||
'name' => $name, | ||
'vector' => $this->vectors[$name], | ||
]; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return $this->vectors; | ||
} | ||
|
||
public function count(): int | ||
{ | ||
return count($this->vectors); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Qdrant\Models; | ||
|
||
interface VectorStructInterface | ||
{ | ||
/** | ||
* Get the name of the vector | ||
* | ||
* @return string | ||
*/ | ||
public function getName(): string; | ||
|
||
/** | ||
* Convert this vector to a search array. | ||
* | ||
* @param string|null $name | ||
* @return array | ||
*/ | ||
public function toSearchArray(string $name = null): array; | ||
|
||
/** | ||
* Convert this vector an array for Point and PointsBatch. | ||
* | ||
* @return array | ||
*/ | ||
public function toArray(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.