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

Conversation

heyjorgedev
Copy link
Contributor

No description provided.

Copy link

linear bot commented Jan 22, 2025

@heyjorgedev heyjorgedev changed the title wip PHP - Vector SDK Docs Jan 22, 2025
@heyjorgedev heyjorgedev changed the title PHP - Vector SDK Docs docs: vector sdk for php Jan 22, 2025
## Install

```shell composer
composer require upstash/vector
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 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.

@yunusemreozdemir
Copy link
Contributor

Just making sure, Resumable Query and Range operations are not yet available in the SDK right?

@yunusemreozdemir
Copy link
Contributor

Can we add PHP to the code examples in Vector->Overall->Getting Started

@yunusemreozdemir
Copy link
Contributor

Can we mention the PHP and Laravel SDKs in the Vector->Overall->Changelog.

@yunusemreozdemir
Copy link
Contributor

Can we add PHP to the code examples in the following pages under Vector->Features:

  • Hybrid Indexes
  • Sparse Indexes
  • Metadata and Data
  • Metadata Filtering
  • Embedding Models
  • Namespaces
  • Resumable Query (If implemented in the SDK)

@yunusemreozdemir
Copy link
Contributor

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.

@yunusemreozdemir
Copy link
Contributor

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?

@yunusemreozdemir
Copy link
Contributor

Can we add PHP to the code examples in the following pages under Vector->Features:

  • Hybrid Indexes
  • Sparse Indexes
  • Metadata and Data
  • Metadata Filtering
  • Embedding Models
  • Namespaces
  • Resumable Query (If implemented in the SDK)

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

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.

vector/sdks/php/commands/upsert-vectors.mdx Outdated Show resolved Hide resolved

## Hybrid Indexes

If your vector index is configured to use hybrid indexes, you need to provide both sparse vectors and dense vectors.
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
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:
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
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:

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 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(
Copy link
Contributor

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.
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
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:
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
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(
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 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.
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 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.

Copy link
Contributor

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

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.

Copy link
Contributor

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(
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'],
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.


$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 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.
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
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.
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.

// 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.

$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.

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.

@yunusemreozdemir
Copy link
Contributor

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.

@heyjorgedev
Copy link
Contributor Author

Just making sure, Resumable Query and Range operations are not yet available in the SDK right?

That's right

@heyjorgedev
Copy link
Contributor Author

Can we add PHP to the code examples in Vector->Overall->Getting Started

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

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants