Skip to content
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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Binary file added img/vector/getstarted/browser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed img/vector/getstarted/charts.png
Binary file not shown.
Binary file modified img/vector/getstarted/create_index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/vector/getstarted/select_plan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/vector/getstarted/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,24 @@
}
]
},
{
"group": "PHP",
"pages": [
"vector/sdks/php/getting-started",
{
"group": "Guides",
"pages": [
"vector/sdks/php/commands/upsert-vectors",
"vector/sdks/php/commands/upsert-data",
"vector/sdks/php/commands/query",
"vector/sdks/php/commands/fetch",
"vector/sdks/php/commands/delete-vectors",
"vector/sdks/php/commands/reset",
"vector/sdks/php/commands/info"
]
}
]
},
"vector/sdk/semantic-cache-js",
"vector/sdk/semantic-cache-py",
"vector/sdk/gosdk"
Expand Down
62 changes: 55 additions & 7 deletions vector/overall/getstarted.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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" />
28 changes: 28 additions & 0 deletions vector/sdks/php/commands/delete-vectors.mdx
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']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before:

Maybe we can move this to a Code Group tab called Namespace.

```

You can read more about [Namespaces](/vector/features/namespaces) on our docs.
37 changes: 37 additions & 0 deletions vector/sdks/php/commands/fetch.mdx
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before:

I think we should have a Response section in this page that is detailing the response that will be returned with an example preferably from a Hybrid index. Since looking at all the includeMetadata, includeData, includeVectors options can be confusing without a concrete response to understand them.

));
// or within a namespace
$results = $index->namespace('my-namespace')->fetch(new VectorFetch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned before:

Maybe we can move this to a Code Group tab called Namespace.

ids: ['1', '2'],
includeVectors: true,
));
```

The `fetch()` method returns a `Upstash\Vector\VectorFetchResult` object, which allows you to access the results of the query.
87 changes: 87 additions & 0 deletions vector/sdks/php/commands/info.mdx
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// To know the number of vector that are getting indexed.
// To know the number of vectors that are getting indexed.

$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;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// To know the number of vector that are getting indexed.
// To know the number of vectors that are getting indexed.

$myNamespaceInfo->pendingVectorCount;
```
Loading