File tree Expand file tree Collapse file tree 6 files changed +61
-4
lines changed Expand file tree Collapse file tree 6 files changed +61
-4
lines changed Original file line number Diff line number Diff line change 9
9
use Upstash \Vector \NamespaceInfo ;
10
10
use Upstash \Vector \VectorDeleteResult ;
11
11
use Upstash \Vector \VectorFetch ;
12
+ use Upstash \Vector \VectorFetchByPrefix ;
12
13
use Upstash \Vector \VectorFetchResult ;
13
14
use Upstash \Vector \VectorMatch ;
14
15
use Upstash \Vector \VectorQuery ;
@@ -55,7 +56,7 @@ public function queryData(DataQuery $query): DataQueryResult;
55
56
*/
56
57
public function delete (array $ ids ): VectorDeleteResult ;
57
58
58
- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult ;
59
+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult ;
59
60
60
61
public function random (): ?VectorMatch ;
61
62
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ public function delete(array $ids): VectorDeleteResult
118
118
return $ this ->namespace ('' )->delete ($ ids );
119
119
}
120
120
121
- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
121
+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
122
122
{
123
123
return $ this ->namespace ('' )->fetch ($ vectorFetch );
124
124
}
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ public function delete(array $ids): VectorDeleteResult
79
79
->delete ($ ids );
80
80
}
81
81
82
- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
82
+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
83
83
{
84
84
return (new FetchVectorsOperation ($ this ->namespace , $ this ->transporter ))
85
85
->fetch ($ vectorFetch );
Original file line number Diff line number Diff line change 10
10
use Upstash \Vector \Transporter \TransporterRequest ;
11
11
use Upstash \Vector \Transporter \TransporterResponse ;
12
12
use Upstash \Vector \VectorFetch ;
13
+ use Upstash \Vector \VectorFetchByPrefix ;
13
14
use Upstash \Vector \VectorFetchResult ;
14
15
use Upstash \Vector \VectorMatch ;
15
16
23
24
24
25
public function __construct (private string $ namespace , private TransporterInterface $ transporter ) {}
25
26
26
- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
27
+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
27
28
{
28
29
$ path = $ this ->getPath ();
29
30
$ request = new TransporterRequest (
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Upstash \Vector ;
4
+
5
+ use Upstash \Vector \Contracts \Arrayable ;
6
+
7
+ final readonly class VectorFetchByPrefix implements Arrayable
8
+ {
9
+ public function __construct (
10
+ public string $ prefix ,
11
+ public bool $ includeMetadata = false ,
12
+ public bool $ includeVectors = false ,
13
+ public bool $ includeData = false ,
14
+ ) {}
15
+
16
+ /**
17
+ * @return array{
18
+ * prefix: string,
19
+ * includeMetadata: bool,
20
+ * includeVectors: bool,
21
+ * includeData: bool,
22
+ * }
23
+ */
24
+ public function toArray (): array
25
+ {
26
+ return [
27
+ 'prefix ' => $ this ->prefix ,
28
+ 'includeMetadata ' => $ this ->includeMetadata ,
29
+ 'includeVectors ' => $ this ->includeVectors ,
30
+ 'includeData ' => $ this ->includeData ,
31
+ ];
32
+ }
33
+ }
Original file line number Diff line number Diff line change 6
6
use Upstash \Vector \Tests \Concerns \UsesDenseIndex ;
7
7
use Upstash \Vector \Tests \Concerns \WaitsForIndex ;
8
8
use Upstash \Vector \VectorFetch ;
9
+ use Upstash \Vector \VectorFetchByPrefix ;
9
10
use Upstash \Vector \VectorUpsert ;
10
11
11
12
use function Upstash \Vector \createRandomVector ;
@@ -16,6 +17,27 @@ class FetchVectorsOperationTest extends TestCase
16
17
use WaitsForIndex;
17
18
18
19
public function test_can_fetch_vectors (): void
20
+ {
21
+ // Arrange
22
+ $ this ->namespace ->upsertMany ([
23
+ new VectorUpsert (id: 'user:1 ' , vector: createRandomVector (2 )),
24
+ new VectorUpsert (id: 'user:2 ' , vector: createRandomVector (2 )),
25
+ new VectorUpsert (id: 'test:3 ' , vector: createRandomVector (2 )),
26
+ ]);
27
+ $ this ->waitForIndex ($ this ->namespace );
28
+
29
+ // Act
30
+ $ results = $ this ->namespace ->fetch (new VectorFetchByPrefix (
31
+ prefix: 'user: ' ,
32
+ includeVectors: true ,
33
+ ));
34
+
35
+ // Assert
36
+ $ this ->assertCount (2 , $ results );
37
+ $ this ->assertCount (2 , $ results [0 ]->vector );
38
+ }
39
+
40
+ public function test_can_fetch_vectors_using_a_filter (): void
19
41
{
20
42
// Arrange
21
43
$ this ->namespace ->upsertMany ([
You can’t perform that action at this time.
0 commit comments