Skip to content

Commit 5dc2c17

Browse files
garvit-guptaOxyjun
andauthored
VS-284: Update docs to include Vectorize queryById operation (#17591)
Co-authored-by: Jun Lee <[email protected]>
1 parent a5a8582 commit 5dc2c17

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

src/content/docs/vectorize/best-practices/query-vectors.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ This would return a set of matches resembling the following, based on the distan
6767

6868
Refer to [Vectorize API](/vectorize/reference/client-api/) for additional examples.
6969

70+
## Query by vector identifier
71+
72+
Vectorize now offers the ability to search for vectors similar to a vector that is already present in the index using the `queryById()` operation. This can be considered as a single operation that combines the `getById()` and the `query()` operation.
73+
74+
```ts
75+
// the query operation would yield results if a vector with id `some-vector-id` is already present in the index.
76+
let matches = await env.YOUR_INDEX.queryById("some-vector-id");
77+
```
78+
7079
## Control over scoring precision and query accuracy
7180

7281
When querying vectors, you can specify to either use high-precision scoring, thereby increasing the precision of the query matches scores as well as the accuracy of the query results, or use approximate scoring for faster response times.

src/content/docs/vectorize/get-started/intro.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ export default {
395395
} satisfies ExportedHandler<Env>;
396396
```
397397

398+
You can also use the Vectorize `queryById()` operation to search for vectors similar to a vector that is already present in the index.
399+
398400
## 7. Deploy your Worker
399401

400402
Before deploying your Worker globally, log in with your Cloudflare account by running:

src/content/docs/vectorize/reference/client-api.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ For legacy Vectorize (V1) indexes, `topK` is limited to 20, and the `returnMetad
8383

8484
:::
8585

86+
### Query vectors by ID
87+
88+
```ts
89+
let matches = await env.YOUR_INDEX.queryById("some-vector-id");
90+
```
91+
92+
Query an index using a vector that is already present in the index.
93+
94+
Query options remain the same as the query operation described above.
95+
96+
```ts
97+
let matches = await env.YOUR_INDEX.queryById("some-vector-id", {
98+
topK: 5,
99+
returnValues: true,
100+
returnMetadata: "all",
101+
});
102+
```
103+
86104
### Get vectors by ID
87105

88106
```ts

src/content/docs/workers/wrangler/commands.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ wrangler docs [<COMMAND>]
139139

140140
## `init`
141141

142+
:::note
143+
144+
The `init` command will be removed in a future version. Please use `npm create cloudflare@latest` instead.
145+
146+
:::
147+
142148
Create a new project via the [create-cloudflare-cli (C3) tool](/workers/get-started/guide/#1-create-a-new-worker-project). A variety of web frameworks are available to choose from as well as templates. Dependencies are installed by default, with the option to deploy your project immediately.
143149

144150
```txt
@@ -591,8 +597,10 @@ npx wrangler vectorize query <INDEX_NAME> [OPTIONS]
591597

592598
- `INDEX_NAME` <Type text="string" /> <MetaInfo text="required" />
593599
- The name of the Vectorize index to query.
594-
- `--vector` <Type text="array" /> <MetaInfo text="required" />
595-
- Vector against which the Vectorize index is queried.
600+
- `--vector` <Type text="array" /> <MetaInfo text="optional" />
601+
- Vector against which the Vectorize index is queried. Either this or the `vector-id` param must be provided.
602+
- `--vector-id` <Type text="string" /> <MetaInfo text="optional" />
603+
- Identifier for a vector that is already present in the index against which the index is queried. Either this or the `vector` param must be provided.
596604
- `--top-k` <Type text="number" /> <MetaInfo text="optional" />
597605
- The number of vectors to query (default: `5`).
598606
- `--return-values` <Type text="boolean" /> <MetaInfo text="optional" />

0 commit comments

Comments
 (0)