-
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?
Conversation
## Install | ||
|
||
```shell composer | ||
composer require upstash/vector |
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.
I think we should also mention the upstash/vector-laravel and its setup here. One way could be turning the code examples in this page to code groups and having PHP and Laravel tabs. For reference you can check out Code Groups Documentation.
Just making sure, Resumable Query and Range operations are not yet available in the SDK right? |
Can we add PHP to the code examples in Vector->Overall->Getting Started |
Can we mention the PHP and Laravel SDKs in the Vector->Overall->Changelog. |
Can we add PHP to the code examples in the following pages under Vector->Features:
|
This can be done in the future in another PR: I think we should add at least one example and one tutorial with PHP under Vector->Examples and Vector->Tutorials respectively. |
Just making sure, we don't have something similar to Index level types and Command level types stated under TypeScript Usage as PHP doesn't have generics right? |
There are references to these pages in the new guides, if for some reason we decide to merge this PR with these pages to be implemented in the future, we need to make sure guides present an understandable flow even with these references missing code examples. |
]); | ||
``` | ||
|
||
Upserting multiple records simultaneously improves performance by allowing you to batch your imports efficiently. |
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.
Can we revisit this sentence? We can use something else instead of imports
. Maybe we can also provide a better explanation of why batch requests improve the performance, such as reducing network overheads. I would think someone from the core team may provide a better explanation.
|
||
## Hybrid Indexes | ||
|
||
If your vector index is configured to use hybrid indexes, you need to provide both sparse vectors and dense vectors. |
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.
If your vector index is configured to use hybrid indexes, you need to provide both sparse vectors and dense vectors. | |
If you are using a hybrid index, you need to provide both sparse vectors and dense vectors. |
|
||
With Upstash Vector, you can upsert one or more vectors. For now, let’s focus on upserting a single vector. | ||
|
||
We’ll use the `upsert()` method to instruct the SDK to upsert vectors into an index, as shown below: |
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.
We’ll use the `upsert()` method to instruct the SDK to upsert vectors into an index, as shown below: | |
We’ll use the `upsert()` method to instruct the SDK to upsert or update vectors into an index, as shown below: |
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.
I think we can have an Update
section after the Upsert Many
that explains you can update your vectors simply with these operations.
data: 'The capital of Japan is Tokyo', | ||
)); | ||
// or within a namespace | ||
$index->namespace('my-namespace')->upsertData(new DataUpsert( |
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.
Not sure about this being here, maybe we can turn this into a Code Group and have a separate tab for the namespace example.
title: Upserting Vectors with Embedded Models | ||
--- | ||
|
||
Upstash Vector includes embedded models that can automatically generate vector embeddings for you. |
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.
Upstash Vector includes embedded models that can automatically generate vector embeddings for you. | |
Upstash Vector provides embedding models that can automatically generate vector embeddings for you. |
|
||
## Upsert Data | ||
|
||
We’ll use the `upsertData()` method to instruct the SDK to upsert data that generates vectors from one of our embedding models, as demonstrated below: |
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.
We’ll use the `upsertData()` method to instruct the SDK to upsert data that generates vectors from one of our embedding models, as demonstrated below: | |
We’ll use the `upsertData()` method to instruct the SDK to upsert or update data that generates vectors from one of our embedding models, as demonstrated below: |
vector: [0.1, 0.2, ...], // "..." represents the dimension size of your vector index. | ||
)); | ||
// or within a namespace | ||
$index->namespace('my-namespace')->upsert(new VectorUpsert( |
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, maybe we can turn this into a Code Group and have a separate tab for namespace.
topK: 15, // topK is the limit number of records we want to be returned. | ||
includeMetadata: true, // (optional) if true the query results will contain metadata. | ||
includeVectors: true, // (optional) if true the query results will contain the indexed vectors. | ||
includeData: true, // (optional) if true the query results will contain the string data. |
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.
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.
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.
Just to be sure, we can't implement something similar to Improved Typechecking example in the TypeScript since PHP doesn't have generics right?
includeData: true, // (optional) if true the query results will contain the string data. | ||
filter: '', // (optional) if set, the query results will be filtered by the given filter. | ||
)); | ||
// or within a namespace |
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.
Maybe we can move this to a Code Group tab called Namespace.
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.
Let's also add the following information boxes to this page:
The dimension of the query vector must match the dimension of your index.
The score returned from query requests is a normalized value between 0 and 1, where 1 indicates the highest similarity and 0 the lowest regardless of the similarity function used.
includeData: true, // (optional) if true the fetch results will contain the string data. | ||
)); | ||
// 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 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'], | ||
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 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.
|
||
$index->delete(['1', '2', '3']); | ||
// or within a namespace | ||
$index->namespace('my-namespace')->delete(['1', '2', '3']); |
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:
Maybe we can move this to a Code Group tab called Namespace.
|
||
You can reset a namespace by calling the `reset()` method on the index or namespace. | ||
|
||
If the `reset()` method is called on the index, only the default namespace will be reseted, not the whole index. |
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.
If the `reset()` method is called on the index, only the default namespace will be reseted, not the whole index. | |
If the `reset()` method is called on the index, only the default namespace will be reset, not the whole index. |
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
// To know the number of vector that are getting indexed. | |
// To know the number of vectors that are getting indexed. |
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
// To know the number of vector that are getting indexed. | |
// To know the number of vectors that are getting indexed. |
$info->similarityFunction; | ||
|
||
// List of namespaces. | ||
$namespaces = $info->namespaces; |
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.
I think this is not a list of namespaces but a mapping of namespaces to their information that contains vectorCount and 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.
I think we should have example responses for index info and namespace info.
We have a Contributing page in TypeScript. You can add one to PHP if you want, though it is more important to have this in the repositories. |
That's right |
Great suggestion! Done |
Co-authored-by: Yunus Emre Özdemir <[email protected]>
|
||
$results = $index->queryData(new DataQuery( | ||
data: 'What is the capital of France?', | ||
topK: 1, // to only return 1 result. |
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.
One small detail, let's set includeData
to true
here so someone trying this example can see the results right away!
No description provided.