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 99use Upstash \Vector \NamespaceInfo ;
1010use Upstash \Vector \VectorDeleteResult ;
1111use Upstash \Vector \VectorFetch ;
12+ use Upstash \Vector \VectorFetchByPrefix ;
1213use Upstash \Vector \VectorFetchResult ;
1314use Upstash \Vector \VectorMatch ;
1415use Upstash \Vector \VectorQuery ;
@@ -55,7 +56,7 @@ public function queryData(DataQuery $query): DataQueryResult;
5556 */
5657 public function delete (array $ ids ): VectorDeleteResult ;
5758
58- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult ;
59+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult ;
5960
6061 public function random (): ?VectorMatch ;
6162
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ public function delete(array $ids): VectorDeleteResult
118118 return $ this ->namespace ('' )->delete ($ ids );
119119 }
120120
121- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
121+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
122122 {
123123 return $ this ->namespace ('' )->fetch ($ vectorFetch );
124124 }
Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ public function delete(array $ids): VectorDeleteResult
7979 ->delete ($ ids );
8080 }
8181
82- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
82+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
8383 {
8484 return (new FetchVectorsOperation ($ this ->namespace , $ this ->transporter ))
8585 ->fetch ($ vectorFetch );
Original file line number Diff line number Diff line change 1010use Upstash \Vector \Transporter \TransporterRequest ;
1111use Upstash \Vector \Transporter \TransporterResponse ;
1212use Upstash \Vector \VectorFetch ;
13+ use Upstash \Vector \VectorFetchByPrefix ;
1314use Upstash \Vector \VectorFetchResult ;
1415use Upstash \Vector \VectorMatch ;
1516
2324
2425 public function __construct (private string $ namespace , private TransporterInterface $ transporter ) {}
2526
26- public function fetch (VectorFetch $ vectorFetch ): VectorFetchResult
27+ public function fetch (VectorFetch | VectorFetchByPrefix $ vectorFetch ): VectorFetchResult
2728 {
2829 $ path = $ this ->getPath ();
2930 $ 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 66use Upstash \Vector \Tests \Concerns \UsesDenseIndex ;
77use Upstash \Vector \Tests \Concerns \WaitsForIndex ;
88use Upstash \Vector \VectorFetch ;
9+ use Upstash \Vector \VectorFetchByPrefix ;
910use Upstash \Vector \VectorUpsert ;
1011
1112use function Upstash \Vector \createRandomVector ;
@@ -16,6 +17,27 @@ class FetchVectorsOperationTest extends TestCase
1617 use WaitsForIndex;
1718
1819 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
1941 {
2042 // Arrange
2143 $ this ->namespace ->upsertMany ([
You can’t perform that action at this time.
0 commit comments