From 189e0629781131eb93fadfb0723608fa5472de36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Tue, 7 Jul 2026 14:10:26 +0200 Subject: [PATCH] docs: add @throws ZVecException annotations to all FFI-calling methods (closes #62) - Added @throws ZVecException to ~122 methods across 8 source files - Methods without existing PHPDoc: added single-line /** @throws ZVecException */ - Methods with existing PHPDoc: added @throws inside existing doc block - Skipped: __destruct, __clone, getHandle, ffi, checkStatus, private helpers - All php -l syntax checks pass --- CHANGELOG.md | 7 ++++++ src/ZVec.php | 46 ++++++++++++++++++++++++++++++++++ src/ZVecCollectionStats.php | 4 +++ src/ZVecDoc.php | 6 +++++ src/ZVecFieldSchema.php | 13 ++++++++++ src/ZVecGroupByVectorQuery.php | 15 +++++++++++ src/ZVecIndexParams.php | 6 +++++ src/ZVecSchema.php | 30 ++++++++++++++++++++++ src/ZVecVectorQuery.php | 14 +++++++++++ 9 files changed, 141 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc85e9..6ef3645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **DOC-003: Added `@throws ZVecException` annotations on all FFI-calling methods** (#62) + - Added `@throws ZVecException` to ~122 methods across 8 source files (`ZVec`, `ZVecSchema`, `ZVecDoc`, `ZVecIndexParams`, `ZVecVectorQuery`, `ZVecGroupByVectorQuery`, `ZVecFieldSchema`, `ZVecCollectionStats`) + - Methods without existing PHPDoc: added single-line `/** @throws ZVecException */` annotation + - Methods with existing PHPDoc: added `@throws ZVecException` line inside the existing doc block + - Skipped: `__destruct`, `__clone`, `getHandle()`, `ffi()`, `checkStatus()`, and private helper methods + - All `php -l` syntax checks pass + - **SMELL-008: Made properties private with getters/setters on reranker data classes** (#89) - `ZVecRerankedDoc`: all properties (`$doc`, `$combinedScore`, `$sourceRanks`, `$sourceScores`) are now `private` - Added getters: `getDoc()`, `getCombinedScore()`, `getSourceRanks()`, `getSourceScores()` diff --git a/src/ZVec.php b/src/ZVec.php index d1baa53..b142751 100644 --- a/src/ZVec.php +++ b/src/ZVec.php @@ -272,6 +272,7 @@ private static function parseGroupResult(FFI\CData $result): array return $groups; } + /** @throws ZVecException */ public static function create(string $path, ZVecSchema $schema, bool $readOnly = false, bool $enableMmap = true, int $maxBufferSize = self::DEFAULT_MAX_BUFFER_SIZE): self { $path = self::validateCollectionPath($path); @@ -282,6 +283,7 @@ public static function create(string $path, ZVecSchema $schema, bool $readOnly = return new self($out, $path); } + /** @throws ZVecException */ public static function open(string $path, bool $readOnly = false, bool $enableMmap = true, int $maxBufferSize = self::DEFAULT_MAX_BUFFER_SIZE): self { $path = self::validateCollectionPath($path); @@ -327,6 +329,7 @@ private function __clone() { } + /** @throws ZVecException */ public function close(): void { if ($this->closed || $this->destroyed) { @@ -336,12 +339,14 @@ public function close(): void $this->closed = true; } + /** @throws ZVecException */ public function flush(): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_flush($this->handle)); } + /** @throws ZVecException */ public function optimize(int $concurrency = 0): void { $this->checkClosed(); @@ -376,6 +381,7 @@ public function destroy(): void $this->destroyed = true; } + /** @throws ZVecException */ public function schema(): string { $this->checkClosed(); @@ -395,6 +401,7 @@ public function schema(): string } } + /** @throws ZVecException */ public function path(): string { $this->checkClosed(); @@ -416,6 +423,8 @@ public function path(): string /** * @return array{read_only: bool, enable_mmap: bool, max_buffer_size: int} + + * @throws ZVecException */ public function options(): array { @@ -432,60 +441,70 @@ public function options(): array ]; } + /** @throws ZVecException */ public function addColumnInt64(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_int64($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnFloat(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_float($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnDouble(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_double($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnString(string $name, bool $nullable = true, string $defaultExpr = '', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_string($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnBool(string $name, bool $nullable = true, string $defaultExpr = 'false', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_bool($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnInt32(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_int32($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnUint32(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_uint32($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function addColumnUint64(string $name, bool $nullable = true, string $defaultExpr = '0', int $concurrency = 0): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_add_column_uint64($this->handle, $name, $nullable ? 1 : 0, $defaultExpr, $concurrency)); } + /** @throws ZVecException */ public function dropColumn(string $name): void { $this->checkClosed(); self::checkStatus(self::ffi()->zvec_collection_drop_column($this->handle, $name)); } + /** @throws ZVecException */ public function renameColumn(string $oldName, string $newName, int $concurrency = 0): void { $this->checkClosed(); @@ -512,6 +531,7 @@ public function alterColumn(string $columnName, ?string $newName = null, ?int $n self::checkStatus(self::ffi()->zvec_collection_alter_column($this->handle, $columnName, $rename, $dataType, $isNullable, $concurrency)); } + /** @throws ZVecException */ public function dropIndex(string $fieldName): void { $this->checkClosed(); @@ -520,6 +540,8 @@ public function dropIndex(string $fieldName): void /** * Create an index using the unified IndexParams API. + + * @throws ZVecException */ public function createIndex(string $fieldName, ZVecIndexParams $params, int $concurrency = 0): void { @@ -571,8 +593,10 @@ private function writeDocs(string $operation, ZVecDoc ...$docs): void public function insert(ZVecDoc ...$docs): void { $this->writeDocs('insert', ...$docs); } + /** @throws ZVecException */ public function upsert(ZVecDoc ...$docs): void { $this->writeDocs('upsert', ...$docs); } + /** @throws ZVecException */ public function update(ZVecDoc ...$docs): void { $this->writeDocs('update', ...$docs); } /** @@ -634,6 +658,7 @@ public function delete(string ...$pks): void } } + /** @throws ZVecException */ public function deleteByFilter(string $filter): void { $this->checkClosed(); @@ -642,6 +667,7 @@ public function deleteByFilter(string $filter): void /** * @return ZVecDoc[] + * @throws ZVecException */ public function fetch(string ...$pks): array { @@ -834,6 +860,8 @@ public static function init( * Check whether the zvec library has been initialized. * * @return bool true if init() was called successfully, false otherwise. + + * @throws ZVecException */ public static function isInitialized(): bool { @@ -855,6 +883,8 @@ public static function shutdown(): void /** * @return array{code: int, message: ?string, file: ?string, line: int, function: ?string} + + * @throws ZVecException */ public static function getLastErrorDetails(): array { @@ -878,31 +908,37 @@ public static function getLastErrorDetails(): array return $result; } + /** @throws ZVecException */ public static function clearError(): void { self::ffi()->zvec_clear_error(); } + /** @throws ZVecException */ public static function getVersion(): string { return self::ffi()->zvec_get_version(); } + /** @throws ZVecException */ public static function checkVersion(int $major, int $minor, int $patch): bool { return self::ffi()->zvec_check_version($major, $minor, $patch) !== 0; } + /** @throws ZVecException */ public static function getVersionMajor(): int { return self::ffi()->zvec_get_version_major(); } + /** @throws ZVecException */ public static function getVersionMinor(): int { return self::ffi()->zvec_get_version_minor(); } + /** @throws ZVecException */ public static function getVersionPatch(): int { return self::ffi()->zvec_get_version_patch(); @@ -912,6 +948,8 @@ public static function getVersionPatch(): int * Query using a native ZVecVectorQuery object. * * @return ZVecDoc[] + + * @throws ZVecException */ public function queryVector(ZVecVectorQuery $query): array { @@ -929,6 +967,8 @@ public function queryVector(ZVecVectorQuery $query): array * GroupBy query using a native ZVecGroupByVectorQuery object. * * @return array + + * @throws ZVecException */ public function groupByVectorQuery(ZVecGroupByVectorQuery $query): array { @@ -1254,6 +1294,7 @@ public function queryFp16( * @param string[]|null $outputFields * @return ZVecDoc[] * @deprecated Use queryWithReranker() when passing a $reranker. The $reranker parameter is deprecated. + * @throws ZVecException */ public function queryFp64( string $fieldName, @@ -1675,6 +1716,7 @@ public function groupByQuery( return $groups; } + /** @throws ZVecException */ public function stats(): string { $this->checkClosed(); @@ -1696,6 +1738,8 @@ public function stats(): string /** * Get structured collection stats. + + * @throws ZVecException */ public function getStatsStruct(): ZVecCollectionStats { @@ -1708,6 +1752,8 @@ public function getStatsStruct(): ZVecCollectionStats /** * Get structured field schema for a specific field. + + * @throws ZVecException */ public function getFieldSchema(string $fieldName): ZVecFieldSchema { diff --git a/src/ZVecCollectionStats.php b/src/ZVecCollectionStats.php index d27c500..1710409 100644 --- a/src/ZVecCollectionStats.php +++ b/src/ZVecCollectionStats.php @@ -35,16 +35,19 @@ private function __clone() { } + /** @throws ZVecException */ public function getDocCount(): int { return self::ffi()->zvec_collection_stats_get_doc_count($this->handle); } + /** @throws ZVecException */ public function getIndexCount(): int { return self::ffi()->zvec_collection_stats_get_index_count($this->handle); } + /** @throws ZVecException */ public function getIndexName(int $index): string { $ptr = self::ffi()->zvec_collection_stats_get_index_name($this->handle, $index); @@ -54,6 +57,7 @@ public function getIndexName(int $index): string return is_string($ptr) ? $ptr : FFI::string($ptr); } + /** @throws ZVecException */ public function getIndexCompleteness(int $index): float { return self::ffi()->zvec_collection_stats_get_index_completeness($this->handle, $index); diff --git a/src/ZVecDoc.php b/src/ZVecDoc.php index ddc8094..b7a38d2 100644 --- a/src/ZVecDoc.php +++ b/src/ZVecDoc.php @@ -163,6 +163,8 @@ public function setVectorFp16(string $field, array $vector): self /** * @param int[] $indices * @param float[] $values + + * @throws ZVecException */ public function setSparseVectorFp32(string $field, array $indices, array $values): self { @@ -253,6 +255,8 @@ public function setVectorBinary64(string $field, array $data): self /** * @param int[] $indices * @param int[] $values (FP16 raw uint16 values) + + * @throws ZVecException */ public function setSparseVectorFp16(string $field, array $indices, array $values): self { @@ -1005,6 +1009,7 @@ public function merge(ZVecDoc $other): self return $this; } + /** @throws ZVecException */ public function serialize(): string { $ffi = self::ffi(); @@ -1026,6 +1031,7 @@ public function serialize(): string * uses an internal serialization format with no integrity checking * or authentication. Deserializing malicious data may cause * undefined behavior or crashes in the C++ layer. + * @throws ZVecException On deserialization failure */ public static function deserialize(string $data): self { diff --git a/src/ZVecFieldSchema.php b/src/ZVecFieldSchema.php index 8b070c3..5f0e052 100644 --- a/src/ZVecFieldSchema.php +++ b/src/ZVecFieldSchema.php @@ -36,67 +36,80 @@ private function __clone() { } + /** @throws ZVecException */ public function getName(): string { $ptr = self::ffi()->zvec_field_schema_get_name($this->handle); return is_string($ptr) ? $ptr : FFI::string($ptr); } + /** @throws ZVecException */ public function getDataType(): int { return self::ffi()->zvec_field_schema_get_data_type($this->handle); } + /** @throws ZVecException */ public function getElementDataType(): int { return self::ffi()->zvec_field_schema_get_element_data_type($this->handle); } + /** @throws ZVecException */ public function getElementDataSize(): int { return self::ffi()->zvec_field_schema_get_element_data_size($this->handle); } + /** @throws ZVecException */ public function getDimension(): int { return self::ffi()->zvec_field_schema_get_dimension($this->handle); } + /** @throws ZVecException */ public function isVectorField(): bool { return self::ffi()->zvec_field_schema_is_vector_field($this->handle) !== 0; } + /** @throws ZVecException */ public function isDenseVector(): bool { return self::ffi()->zvec_field_schema_is_dense_vector($this->handle) !== 0; } + /** @throws ZVecException */ public function isSparseVector(): bool { return self::ffi()->zvec_field_schema_is_sparse_vector($this->handle) !== 0; } + /** @throws ZVecException */ public function isArrayType(): bool { return self::ffi()->zvec_field_schema_is_array_type($this->handle) !== 0; } + /** @throws ZVecException */ public function isNullable(): bool { return self::ffi()->zvec_field_schema_is_nullable($this->handle) !== 0; } + /** @throws ZVecException */ public function hasInvertIndex(): bool { return self::ffi()->zvec_field_schema_has_invert_index($this->handle) !== 0; } + /** @throws ZVecException */ public function hasIndex(): bool { return self::ffi()->zvec_field_schema_has_index($this->handle) !== 0; } + /** @throws ZVecException */ public function getIndexType(): int { return self::ffi()->zvec_field_schema_get_index_type($this->handle); diff --git a/src/ZVecGroupByVectorQuery.php b/src/ZVecGroupByVectorQuery.php index 8b38087..5482dc1 100644 --- a/src/ZVecGroupByVectorQuery.php +++ b/src/ZVecGroupByVectorQuery.php @@ -44,6 +44,8 @@ class ZVecGroupByVectorQuery implements ZVecQueryInterface /** * @param float[] $vector + + * @throws ZVecException */ public function __construct(string $fieldName, array $vector, string $groupByField, int $groupCount = 2, int $groupTopk = 3) { @@ -101,6 +103,7 @@ public function getHandle(): FFI\CData return $this->handle; } + /** @throws ZVecException */ public function free(): void { if ($this->closed) { @@ -113,18 +116,21 @@ public function free(): void } } + /** @throws ZVecException */ public function setGroupByField(string $field): self { self::ffi()->zvec_group_by_vector_query_set_group_by_field($this->handle, $field); return $this; } + /** @throws ZVecException */ public function setGroupCount(int $count): self { self::ffi()->zvec_group_by_vector_query_set_group_count($this->handle, $count); return $this; } + /** @throws ZVecException */ public function setGroupTopk(int $topk): self { self::ffi()->zvec_group_by_vector_query_set_group_topk($this->handle, $topk); @@ -133,6 +139,8 @@ public function setGroupTopk(int $topk): self /** * GroupByVectorQuery does not support general topk; use setGroupTopk() instead. + + * @throws ZVecException */ public function setTopk(int $topk): self { @@ -141,6 +149,7 @@ public function setTopk(int $topk): self ); } + /** @throws ZVecException */ public function setRadius(float $radius): self { $this->radius = $radius; @@ -148,6 +157,7 @@ public function setRadius(float $radius): self return $this; } + /** @throws ZVecException */ public function setLinear(bool $linear): self { $this->isLinear = $linear; @@ -155,6 +165,7 @@ public function setLinear(bool $linear): self return $this; } + /** @throws ZVecException */ public function setUsingRefiner(bool $refiner): self { $this->isUsingRefiner = $refiner; @@ -162,12 +173,14 @@ public function setUsingRefiner(bool $refiner): self return $this; } + /** @throws ZVecException */ public function setIncludeVector(bool $include): self { self::ffi()->zvec_group_by_vector_query_set_include_vector($this->handle, $include ? 1 : 0); return $this; } + /** @throws ZVecException */ public function setFilter(string $filter): self { self::ffi()->zvec_group_by_vector_query_set_filter($this->handle, $filter); @@ -176,6 +189,8 @@ public function setFilter(string $filter): self /** * @param string[] $fields + + * @throws ZVecException */ public function setOutputFields(array $fields): self { diff --git a/src/ZVecIndexParams.php b/src/ZVecIndexParams.php index ddf7410..3ed9622 100644 --- a/src/ZVecIndexParams.php +++ b/src/ZVecIndexParams.php @@ -42,6 +42,7 @@ public function getHandle(): FFI\CData return $this->handle; } + /** @throws ZVecException */ public static function forHnsw(int $metricType, int $m = ZVec::DEFAULT_HNSW_M, int $efConstruction = ZVec::DEFAULT_HNSW_EF_CONSTRUCTION, int $quantizeType = ZVec::QUANTIZE_UNDEFINED, bool $useContiguousMemory = false): self { if ($m <= 0) { @@ -56,6 +57,7 @@ public static function forHnsw(int $metricType, int $m = ZVec::DEFAULT_HNSW_M, i return new self($handle); } + /** @throws ZVecException */ public static function forHnswRabitq(int $metricType, int $totalBits = 7, int $numClusters = 16, int $m = ZVec::DEFAULT_HNSW_M, int $efConstruction = ZVec::DEFAULT_HNSW_EF_CONSTRUCTION, int $sampleCount = 0): self { if ($m <= 0) { @@ -70,6 +72,7 @@ public static function forHnswRabitq(int $metricType, int $totalBits = 7, int $n return new self($handle); } + /** @throws ZVecException */ public static function forFlat(int $metricType, int $quantizeType = ZVec::QUANTIZE_UNDEFINED): self { $ffi = self::ffi(); @@ -78,6 +81,7 @@ public static function forFlat(int $metricType, int $quantizeType = ZVec::QUANTI return new self($handle); } + /** @throws ZVecException */ public static function forIvf(int $metricType, int $nList = 1024, int $nIters = 10, bool $useSoar = false, int $quantizeType = ZVec::QUANTIZE_UNDEFINED): self { if ($nList <= 0) { @@ -92,6 +96,7 @@ public static function forIvf(int $metricType, int $nList = 1024, int $nIters = return new self($handle); } + /** @throws ZVecException */ public static function forVamana(int $metricType, int $maxDegree = 64, int $searchListSize = 100, float $alpha = 1.2, bool $saturateGraph = false, bool $useContiguousMemory = false, bool $useIdMap = false, int $quantizeType = ZVec::QUANTIZE_UNDEFINED): self { if ($maxDegree <= 0) { @@ -106,6 +111,7 @@ public static function forVamana(int $metricType, int $maxDegree = 64, int $sear return new self($handle); } + /** @throws ZVecException */ public static function forInvert(bool $enableRange = true, bool $enableWildcard = false): self { $ffi = self::ffi(); diff --git a/src/ZVecSchema.php b/src/ZVecSchema.php index e591563..da529b0 100644 --- a/src/ZVecSchema.php +++ b/src/ZVecSchema.php @@ -25,6 +25,7 @@ class ZVecSchema { private FFI\CData $handle; + /** @throws ZVecException */ public function __construct(string $name) { if ($name === '') { @@ -33,6 +34,7 @@ public function __construct(string $name) $this->handle = self::ffi()->zvec_schema_create($name); } + /** @throws ZVecException */ public function __destruct() { self::ffi()->zvec_schema_free($this->handle); @@ -47,54 +49,63 @@ public function getHandle(): FFI\CData return $this->handle; } + /** @throws ZVecException */ public function setMaxDocCountPerSegment(int $count): self { self::ffi()->zvec_schema_set_max_doc_count_per_segment($this->handle, $count); return $this; } + /** @throws ZVecException */ public function addInt64(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_int64($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addString(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_string($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addFloat(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_float($this->handle, $name, $nullable ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addDouble(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_double($this->handle, $name, $nullable ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addBool(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_bool($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addInt32(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_int32($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addUint32(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_uint32($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); return $this; } + /** @throws ZVecException */ public function addUint64(string $name, bool $nullable = false, bool $withInvertIndex = false): self { self::ffi()->zvec_schema_add_field_uint64($this->handle, $name, $nullable ? 1 : 0, $withInvertIndex ? 1 : 0); @@ -106,6 +117,7 @@ public function addUint64(string $name, bool $nullable = false, bool $withInvert public const METRIC_COSINE = 3; public const METRIC_MIPSL2 = 4; + /** @throws ZVecException */ public function addVectorFp32(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -115,6 +127,7 @@ public function addVectorFp32(string $name, int $dimension, int $metricType = se return $this; } + /** @throws ZVecException */ public function addVectorFp64(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -124,12 +137,14 @@ public function addVectorFp64(string $name, int $dimension, int $metricType = se return $this; } + /** @throws ZVecException */ public function addSparseVectorFp32(string $name, int $metricType = self::METRIC_IP): self { self::ffi()->zvec_schema_add_field_sparse_vector_fp32($this->handle, $name, $metricType); return $this; } + /** @throws ZVecException */ public function addVectorInt8(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -139,6 +154,7 @@ public function addVectorInt8(string $name, int $dimension, int $metricType = se return $this; } + /** @throws ZVecException */ public function addVectorFp16(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -148,6 +164,7 @@ public function addVectorFp16(string $name, int $dimension, int $metricType = se return $this; } + /** @throws ZVecException */ public function addVectorInt4(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -157,6 +174,7 @@ public function addVectorInt4(string $name, int $dimension, int $metricType = se return $this; } + /** @throws ZVecException */ public function addVectorInt16(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -166,6 +184,7 @@ public function addVectorInt16(string $name, int $dimension, int $metricType = s return $this; } + /** @throws ZVecException */ public function addVectorBinary32(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -175,6 +194,7 @@ public function addVectorBinary32(string $name, int $dimension, int $metricType return $this; } + /** @throws ZVecException */ public function addVectorBinary64(string $name, int $dimension, int $metricType = self::METRIC_IP): self { if ($dimension <= 0) { @@ -184,6 +204,7 @@ public function addVectorBinary64(string $name, int $dimension, int $metricType return $this; } + /** @throws ZVecException */ public function addSparseVectorFp16(string $name, int $metricType = self::METRIC_IP): self { self::ffi()->zvec_schema_add_field_sparse_vector_fp16($this->handle, $name, $metricType); @@ -197,6 +218,7 @@ public function addFieldBinary(string $name, bool $nullable = true): self return $this->addBinary($name, $nullable); } + /** @throws ZVecException */ public function addBinary(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_binary($this->handle, $name, $nullable ? 1 : 0); @@ -210,6 +232,7 @@ public function addFieldArrayString(string $name, bool $nullable = true): self return $this->addArrayString($name, $nullable); } + /** @throws ZVecException */ public function addArrayString(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_string($this->handle, $name, $nullable ? 1 : 0); @@ -223,6 +246,7 @@ public function addFieldArrayBool(string $name, bool $nullable = true): self return $this->addArrayBool($name, $nullable); } + /** @throws ZVecException */ public function addArrayBool(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_bool($this->handle, $name, $nullable ? 1 : 0); @@ -236,6 +260,7 @@ public function addFieldArrayInt32(string $name, bool $nullable = true): self return $this->addArrayInt32($name, $nullable); } + /** @throws ZVecException */ public function addArrayInt32(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_int32($this->handle, $name, $nullable ? 1 : 0); @@ -249,6 +274,7 @@ public function addFieldArrayInt64(string $name, bool $nullable = true): self return $this->addArrayInt64($name, $nullable); } + /** @throws ZVecException */ public function addArrayInt64(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_int64($this->handle, $name, $nullable ? 1 : 0); @@ -262,6 +288,7 @@ public function addFieldArrayUint32(string $name, bool $nullable = true): self return $this->addArrayUint32($name, $nullable); } + /** @throws ZVecException */ public function addArrayUint32(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_uint32($this->handle, $name, $nullable ? 1 : 0); @@ -275,6 +302,7 @@ public function addFieldArrayUint64(string $name, bool $nullable = true): self return $this->addArrayUint64($name, $nullable); } + /** @throws ZVecException */ public function addArrayUint64(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_uint64($this->handle, $name, $nullable ? 1 : 0); @@ -288,6 +316,7 @@ public function addFieldArrayFloat(string $name, bool $nullable = true): self return $this->addArrayFloat($name, $nullable); } + /** @throws ZVecException */ public function addArrayFloat(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_float($this->handle, $name, $nullable ? 1 : 0); @@ -301,6 +330,7 @@ public function addFieldArrayDouble(string $name, bool $nullable = true): self return $this->addArrayDouble($name, $nullable); } + /** @throws ZVecException */ public function addArrayDouble(string $name, bool $nullable = true): self { self::ffi()->zvec_schema_add_field_array_double($this->handle, $name, $nullable ? 1 : 0); diff --git a/src/ZVecVectorQuery.php b/src/ZVecVectorQuery.php index afb9c8a..03fe35d 100644 --- a/src/ZVecVectorQuery.php +++ b/src/ZVecVectorQuery.php @@ -50,6 +50,7 @@ class ZVecVectorQuery implements ZVecQueryInterface /** * @param float[] $vector Dense vector data + * @throws ZVecException */ public function __construct(string $fieldName, array $vector) { @@ -122,6 +123,7 @@ public static function fromId(string $fieldName, string $docId): self return $query; } + /** @throws ZVecException */ public function setHnswParams(int $ef): self { $this->queryParamType = ZVec::QUERY_PARAM_HNSW; @@ -130,6 +132,7 @@ public function setHnswParams(int $ef): self return $this; } + /** @throws ZVecException */ public function setHnswRabitqParams(int $ef): self { $this->queryParamType = ZVec::QUERY_PARAM_HNSW_RABITQ; @@ -138,6 +141,7 @@ public function setHnswRabitqParams(int $ef): self return $this; } + /** @throws ZVecException */ public function setIvfParams(int $nprobe): self { $this->queryParamType = ZVec::QUERY_PARAM_IVF; @@ -146,6 +150,7 @@ public function setIvfParams(int $nprobe): self return $this; } + /** @throws ZVecException */ public function setFlatParams(): self { $this->queryParamType = ZVec::QUERY_PARAM_FLAT; @@ -153,6 +158,7 @@ public function setFlatParams(): self return $this; } + /** @throws ZVecException */ public function setVamanaParams(int $efSearch): self { $this->queryParamType = ZVec::QUERY_PARAM_VAMANA; @@ -161,6 +167,7 @@ public function setVamanaParams(int $efSearch): self return $this; } + /** @throws ZVecException */ public function setRadius(float $radius): self { $this->radius = $radius; @@ -168,6 +175,7 @@ public function setRadius(float $radius): self return $this; } + /** @throws ZVecException */ public function setLinear(bool $linear): self { $this->isLinear = $linear; @@ -175,6 +183,7 @@ public function setLinear(bool $linear): self return $this; } + /** @throws ZVecException */ public function setUsingRefiner(bool $refiner): self { $this->isUsingRefiner = $refiner; @@ -182,6 +191,7 @@ public function setUsingRefiner(bool $refiner): self return $this; } + /** @throws ZVecException */ public function setTopk(int $topk): self { $this->topk = $topk; @@ -189,6 +199,7 @@ public function setTopk(int $topk): self return $this; } + /** @throws ZVecException */ public function setIncludeVector(bool $include): self { $this->includeVector = $include; @@ -196,6 +207,7 @@ public function setIncludeVector(bool $include): self return $this; } + /** @throws ZVecException */ public function setFilter(string $filter): self { $this->filter = $filter; @@ -205,6 +217,8 @@ public function setFilter(string $filter): self /** * @param string[] $fields + + * @throws ZVecException */ public function setOutputFields(array $fields): self {