You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.
8
-
9
-
## Installation
7
+
## Quick Start
8
+
### Installation
10
9
11
10
You can install the package via composer:
12
11
13
12
```bash
14
13
composer require upstash/vector
15
14
```
16
15
17
-
## Usage
16
+
### Create Index
17
+
18
+
Create a new index on [Upstash](https://console.upstash.com/vector)
19
+
20
+
### Basic Usage
18
21
19
22
```php
20
-
$index = new Upstash\Vector\Index::fromEnv();
21
-
$index->getInfo();
23
+
use Upstash\Vector\Index;
24
+
25
+
// Initialize the index
26
+
$index = new Index(
27
+
url: '<UPSTASH_VECTOR_REST_URL>',
28
+
token: '<UPSTASH_VECTOR_REST_TOKEN>',
29
+
);
30
+
31
+
// or just to use the environment variables
32
+
$index = Index::fromEnv();
33
+
34
+
// Upsert to dense index
35
+
use Upstash\Vector\VectorUpsert;
36
+
37
+
$index->upsert(new VectorUpsert(
38
+
id: 'upstash-rocks',
39
+
vector: [
40
+
0.13, 0.87, ... // dense embedding
41
+
],
42
+
metadata: [
43
+
'title' => 'Lord of The Rings',
44
+
'genre' => 'fantasy',
45
+
'category' => 'classic',
46
+
],
47
+
));
48
+
49
+
// Upsert data as plain text.
50
+
use Upstash\Vector\DataUpsert;
51
+
52
+
$index->upsertData(new DataUpsert(
53
+
id: 'tokyo',
54
+
data: 'Tokyo is the capital of Japan.',
55
+
));
56
+
57
+
// Query Vector Data
58
+
use Upstash\Vector\VectorQuery;
59
+
60
+
$result = $index->query(new VectorQuery(
61
+
vector: [0.13, 0.87, ...], // dense embedding
62
+
includeVectors: true,
63
+
includeMetadata: true,
64
+
topK: 1,
65
+
));
66
+
67
+
68
+
// Query with your data
69
+
use Upstash\Vector\DataQuery;
70
+
71
+
$result = $index->queryData(new DataQuery(
72
+
data: 'What is the capital of Japan?',
73
+
topK: 1,
74
+
));
22
75
```
23
76
77
+
## Namespaces
78
+
Upstash Vector allows you to partition a single index into multiple isolated namespaces. Each namespace functions as a self-contained subset of the index, in which read and write requests are only limited to one namespace. To learn more about it, see Namespaces
79
+
80
+
### Example
81
+
```php
82
+
use Upstash\Vector\Index;
83
+
84
+
$index = Index::fromEnv();
85
+
86
+
$namespace = $index->namespace('books');
87
+
88
+
// Upsert to namespace
89
+
$namespace->upsert(new VectorUpsert(
90
+
id: 'lord-of-the-rings',
91
+
vector: [0.13, 0.87, ...],
92
+
metadata: [
93
+
'title' => 'Lord of The Rings',
94
+
'genre' => 'fantasy',
95
+
'category' => 'classic',
96
+
],
97
+
));
98
+
```
24
99
## Testing
25
100
26
101
```bash
@@ -30,12 +105,3 @@ composer test
30
105
## Changelog
31
106
32
107
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
33
-
34
-
## Credits
35
-
36
-
-[Jorge Lapa](https://github.com/heyjorgedev)
37
-
-[All Contributors](../../contributors)
38
-
39
-
## License
40
-
41
-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
0 commit comments