Skip to content

Commit 4201e94

Browse files
committed
docs: readme
1 parent 794e31e commit 4201e94

File tree

1 file changed

+81
-15
lines changed

1 file changed

+81
-15
lines changed

README.md

+81-15
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,98 @@
44
[![Tests](https://img.shields.io/github/actions/workflow/status/upstash/vector/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/upstash/vector/actions/workflows/run-tests.yml)
55
[![Total Downloads](https://img.shields.io/packagist/dt/upstash/vector.svg?style=flat-square)](https://packagist.org/packages/upstash/vector)
66

7-
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
109

1110
You can install the package via composer:
1211

1312
```bash
1413
composer require upstash/vector
1514
```
1615

17-
## Usage
16+
### Create Index
17+
18+
Create a new index on [Upstash](https://console.upstash.com/vector)
19+
20+
### Basic Usage
1821

1922
```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+
));
2275
```
2376

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+
```
2499
## Testing
25100

26101
```bash
@@ -30,12 +105,3 @@ composer test
30105
## Changelog
31106

32107
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

Comments
 (0)