-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIndexNamespace.php
More file actions
110 lines (91 loc) · 3.83 KB
/
IndexNamespace.php
File metadata and controls
110 lines (91 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
namespace Upstash\Vector;
use Upstash\Vector\Contracts\IndexNamespaceInterface;
use Upstash\Vector\Contracts\TransporterInterface;
use Upstash\Vector\Iterators\VectorRangeIterator;
use Upstash\Vector\Operations\DeleteNamespaceOperation;
use Upstash\Vector\Operations\DeleteVectorsOperation;
use Upstash\Vector\Operations\FetchRandomVectorOperation;
use Upstash\Vector\Operations\FetchVectorsOperation;
use Upstash\Vector\Operations\GetNamespaceInfoOperation;
use Upstash\Vector\Operations\QueryDataOperation;
use Upstash\Vector\Operations\QueryVectorsManyOperation;
use Upstash\Vector\Operations\QueryVectorsOperation;
use Upstash\Vector\Operations\RangeVectorsOperation;
use Upstash\Vector\Operations\ResetNamespaceOperation;
use Upstash\Vector\Operations\UpdateVectorOperation;
use Upstash\Vector\Operations\UpsertDataOperation;
use Upstash\Vector\Operations\UpsertVectorOperation;
final readonly class IndexNamespace implements IndexNamespaceInterface
{
public function __construct(protected string $namespace, protected TransporterInterface $transporter) {}
public function getNamespaceInfo(): NamespaceInfo
{
return (new GetNamespaceInfoOperation($this->namespace, $this->transporter))->getNamespaceInfo();
}
public function reset(): void
{
(new ResetNamespaceOperation($this->namespace, $this->transporter))->reset();
}
public function deleteNamespace(): void
{
(new DeleteNamespaceOperation($this->namespace, $this->transporter))->delete();
}
public function upsert(VectorUpsert $vector): void
{
(new UpsertVectorOperation($this->namespace, $this->transporter))->upsert($vector);
}
public function upsertMany(array $vectors): void
{
(new UpsertVectorOperation($this->namespace, $this->transporter))->upsertMany($vectors);
}
public function upsertData(DataUpsert $data): void
{
(new UpsertDataOperation($this->namespace, $this->transporter))->upsert($data);
}
public function upsertDataMany(array $data): void
{
(new UpsertDataOperation($this->namespace, $this->transporter))->upsertMany($data);
}
public function query(VectorQuery $query): VectorQueryResult
{
return (new QueryVectorsOperation($this->namespace, $this->transporter))->query($query);
}
public function queryMany(array $queries): VectorQueryManyResult
{
return (new QueryVectorsManyOperation($this->namespace, $this->transporter))->query($queries);
}
public function queryData(DataQuery $query): DataQueryResult
{
return (new QueryDataOperation($this->namespace, $this->transporter))->query($query);
}
/**
* @param string[]|string|VectorDeleteByPrefix|VectorDeleteByMetadataFilter $ids
*/
public function delete(array|string|VectorDeleteByPrefix|VectorDeleteByMetadataFilter $ids): VectorDeleteResult
{
return (new DeleteVectorsOperation($this->namespace, $this->transporter))
->delete($ids);
}
public function fetch(VectorFetch $vectorFetch): VectorFetchResult
{
return (new FetchVectorsOperation($this->namespace, $this->transporter))
->fetch($vectorFetch);
}
public function random(): ?VectorMatch
{
return (new FetchRandomVectorOperation($this->namespace, $this->transporter))->fetch();
}
public function update(VectorUpdate $update): void
{
(new UpdateVectorOperation($this->namespace, $this->transporter))->update($update);
}
public function range(VectorRange $range): VectorRangeResult
{
return (new RangeVectorsOperation($this->namespace, $this->transporter))->range($range);
}
public function rangeIterator(VectorRange $range): VectorRangeIterator
{
return (new RangeVectorsOperation($this->namespace, $this->transporter))->rangeIterator($range);
}
}