-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: vector sdk for php #373
base: main
Are you sure you want to change the base?
Changes from all commits
07f6afc
ecda9b9
a490d4e
057f1c8
e746f73
a11740a
d950d84
c9a4aa1
28618fc
2f70081
7ea9f3a
9e89bdf
7ea194a
23fc10b
b82d84a
bf64dbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,16 @@ Once you logged in, you can create a Vector Index by clicking on the `Create Ind | |
|
||
**Region:** Choose the region for your index. For optimal performance, select the region closest to your applications. We plan to support additional regions and cloud providers. Feel free to send your requests to [[email protected]](mailto:[email protected]) | ||
|
||
**Dimensions:** Select the dimensions and distance metric depending on your model. | ||
**Type:** The type of index: Dense, [Sparse](/vector/features/sparseindexes) or [Hybrid](/vector/features/hybridindexes). For semantic search, you can prefer dense. For full text (or keyword) search, you can prefer sparse. If you need a combination, you can choose hybrid. | ||
|
||
If you choose Dense or Hybrid as index type, you will also be presented with options to select the dimensions and distance metric of your index. | ||
|
||
<Tip> | ||
For the purpose of using the code samples on this page, you can create a dense index with `dimension: 2`. Distance metric can be any of the options. | ||
</Tip> | ||
|
||
|
||
Once you pick these options, you will choose a plan: | ||
|
||
<Frame style={{width: '600px'}}> | ||
<img src="/img/vector/getstarted/select_plan.png" /> | ||
|
@@ -88,6 +97,24 @@ func main() { | |
``` | ||
</Tab> | ||
|
||
<Tab title="PHP"> | ||
```php | ||
use Upstash\Vector\Index; | ||
use Upstash\Vector\VectorUpsert; | ||
|
||
$index = new Index( | ||
url: 'UPSTASH_VECTOR_REST_URL', | ||
token: 'UPSTASH_VECTOR_REST_TOKEN', | ||
); | ||
|
||
$index->upsert(new VectorUpsert( | ||
id: '1', | ||
vector: [0.6, 0.8], | ||
metadata: ['field' => 'value'], | ||
)); | ||
``` | ||
</Tab> | ||
|
||
<Tab title="curl"> | ||
```shell | ||
curl $UPSTASH_VECTOR_REST_URL/upsert \ | ||
|
@@ -154,29 +181,50 @@ func main() { | |
``` | ||
</Tab> | ||
|
||
<Tab title="PHP"> | ||
```php | ||
use Upstash\Vector\Index; | ||
use Upstash\Vector\VectorQuery; | ||
|
||
$index = new Index( | ||
url: '<UPSTASH_VECTOR_REST_URL>', | ||
token: '<UPSTASH_VECTOR_REST_TOKEN>', | ||
); | ||
|
||
$index->query(new VectorQuery( | ||
vector: [0.6, 0.8], | ||
topK: 3, | ||
includeMetadata: true, | ||
)); | ||
``` | ||
</Tab> | ||
|
||
<Tab title="curl"> | ||
```shell | ||
|
||
curl $UPSTASH_VECTOR_REST_URL/query \ | ||
-H "Authorization: Bearer $UPSTASH_VECTOR_REST_TOKEN" \ | ||
-d '{"vector": [0.6, 0.8], "topK": 3, "includeMetadata": "true"}' | ||
``` | ||
</Tab> | ||
|
||
|
||
</Tabs> | ||
|
||
## Charts and Query Browser | ||
## Usage and Data Browser | ||
|
||
In Upstash console, you can see the charts of your index: | ||
|
||
<Frame style={{width: '600px'}}> | ||
<img src="/img/vector/getstarted/charts.png" /> | ||
<img src="/img/vector/getstarted/usage.png" /> | ||
</Frame> | ||
|
||
|
||
In Upstash console, you can see the charts of your index and query your index with a simple UI. There are following charts: | ||
There are following charts: | ||
|
||
- **Daily Requests:** The number of queries and updates to your index in the last 5 days. | ||
- **Throughput:** The number of queries and updates to your index in the selected time period. | ||
- **Latency:** The mean and P99 latency of queries and updates to your index in the selected time period. | ||
- **Vector Count:** The number of vectors in your index in the selected time period. | ||
- **Data Size:** The size of your index in the selected time period. | ||
|
||
You can also query your index with a simple UI: | ||
|
||
<img src="/img/vector/getstarted/browser.png" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: Deleting Vectors | ||
--- | ||
|
||
You can easily delete vectors from our vector database, ensuring your data remains organized and up-to-date. | ||
|
||
Our SDK allows you to delete vector data from indexes and/or namespaces. | ||
|
||
## Delete | ||
|
||
Every vector in our database has an ID defined by you. This ID is used to reference the vectors you want to delete. | ||
|
||
We'll use the `delete()` method to instruct the SDK to delete vectors 1, 2, and 3, as shown below: | ||
|
||
```php | ||
use Upstash\Vector\Index; | ||
|
||
$index = new Index( | ||
url: "<UPSTASH_VECTOR_REST_URL>", | ||
token: "<UPSTASH_VECTOR_REST_TOKEN>", | ||
); | ||
|
||
$index->delete(['1', '2', '3']); | ||
// or within a namespace | ||
$index->namespace('my-namespace')->delete(['1', '2', '3']); | ||
``` | ||
|
||
You can read more about [Namespaces](/vector/features/namespaces) on our docs. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--- | ||
title: Fetching Vectors | ||
--- | ||
|
||
Sometimes, you’re not just searching for something—you know exactly which vector you want to retrieve. | ||
|
||
In such cases, you can directly fetch specific vectors from your database. | ||
|
||
## Fetch | ||
|
||
Each record in Upstash Vector is assigned a unique ID, which you can use to retrieve a specific vector from your database. | ||
|
||
Let's use the `fetch()` method to retrieve a vector from Upstash Vector. | ||
|
||
```php | ||
use Upstash\Vector\Index; | ||
use Upstash\Vector\VectorFetch; | ||
|
||
$index = new Index( | ||
url: "<UPSTASH_VECTOR_REST_URL>", | ||
token: "<UPSTASH_VECTOR_REST_TOKEN>", | ||
); | ||
|
||
$results = $index->fetch(new VectorFetch( | ||
ids: ['1', '2'], | ||
includeMetadata: true, // (optional) if true the fetch results will contain metadata. | ||
includeVectors: true, // (optional) if true the fetch results will contain the indexed vectors. | ||
includeData: true, // (optional) if true the fetch results will contain the string data. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned before:
|
||
)); | ||
// or within a namespace | ||
$results = $index->namespace('my-namespace')->fetch(new VectorFetch( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned before:
|
||
ids: ['1', '2'], | ||
includeVectors: true, | ||
)); | ||
``` | ||
|
||
The `fetch()` method returns a `Upstash\Vector\VectorFetchResult` object, which allows you to access the results of the query. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should have example responses for index info and namespace info. |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,87 @@ | ||||||
--- | ||||||
title: Info | ||||||
--- | ||||||
|
||||||
Your index contains valuable information that may be useful to retrieve for various purposes. | ||||||
|
||||||
Our SDK provides the capability to fetch detailed information about your index, including metadata, | ||||||
ready and pending vectors, similarity function, and associated namespaces. | ||||||
|
||||||
## Index Info | ||||||
|
||||||
To fetch the information about your index you can use the `getInfo()` method as shown below. | ||||||
|
||||||
```php | ||||||
use Upstash\Vector\Index; | ||||||
|
||||||
$index = new Index( | ||||||
url: "<UPSTASH_VECTOR_REST_URL>", | ||||||
token: "<UPSTASH_VECTOR_REST_TOKEN>", | ||||||
); | ||||||
|
||||||
$info = $index->getInfo(); | ||||||
``` | ||||||
|
||||||
That call will return an instance of `Upstash\Vector\IndexInfo`. | ||||||
|
||||||
We can use index info as follows: | ||||||
|
||||||
```php | ||||||
// To know the number of vectors ready to query. | ||||||
$info->vectorCount; | ||||||
|
||||||
// To know the number of vector that are getting indexed. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$info->pendingVectorCount; | ||||||
|
||||||
// To know the size of the index in bytes. | ||||||
$info->indexSize; | ||||||
|
||||||
// To know the dimensions of your vector index. | ||||||
$info->dimension; | ||||||
|
||||||
// To know which similarity function is being used. | ||||||
$info->similarityFunction; | ||||||
|
||||||
// List of namespaces. | ||||||
$namespaces = $info->namespaces; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is not a list of namespaces but a mapping of namespaces to their information that contains vectorCount and pendingVectorCount. |
||||||
|
||||||
// To get information about a specific index you can (More on next section): | ||||||
$namespaceInfo = $info->namespace('my-namespace'); | ||||||
``` | ||||||
|
||||||
You can read more about [Namespaces](/vector/features/namespaces) and [Similarity Functions](/vector/features/similarityfunctions) on our docs. | ||||||
|
||||||
## Namespace Info | ||||||
|
||||||
Namespaces also contain vectors, which may be pending indexing. | ||||||
|
||||||
As shown above, you can fetch information about the namespaces when making a `getInfo()` call on the index. | ||||||
|
||||||
Additionally, you can use the `getNamespaceInfo()` method: | ||||||
|
||||||
```php | ||||||
use Upstash\Vector\Index; | ||||||
|
||||||
$index = new Index( | ||||||
url: "<UPSTASH_VECTOR_REST_URL>", | ||||||
token: "<UPSTASH_VECTOR_REST_TOKEN>", | ||||||
); | ||||||
|
||||||
// Fetch the information of the default namespace. | ||||||
$defaultNamespaceInfo = $index->getNamespaceInfo(); | ||||||
|
||||||
// Fetch the information on a specific namespace. | ||||||
$myNamespaceInfo = $index->namespace('my-namespace')->getNamespaceInfo(); | ||||||
``` | ||||||
|
||||||
The `getNamespaceInfo()` call will return an instance of `Upstash\Vector\NamespaceInfo`. | ||||||
|
||||||
We can use namespace info as follows: | ||||||
|
||||||
```php | ||||||
// To know the number of vectors ready to query. | ||||||
$myNamespaceInfo->vectorCount; | ||||||
|
||||||
// To know the number of vector that are getting indexed. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$myNamespaceInfo->pendingVectorCount; | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned before: