Skip to content

Commit ce871f9

Browse files
committed
VS-284: Update docs to include Vectorize queryById operation
1 parent 0cc038b commit ce871f9

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,9 @@ wrangler docs [<COMMAND>]
138138

139139
## `init`
140140

141-
:::note
142-
143-
144-
The `init` command will be removed in a future version. Please use `npm create cloudflare@latest` instead.
141+
:::note
145142

143+
The `init` command will be removed in a future version. Please use `npm create cloudflare@latest` instead.
146144

147145
:::
148146

@@ -596,8 +594,10 @@ npx wrangler vectorize query <INDEX_NAME> [OPTIONS]
596594

597595
- `INDEX_NAME` <Type text="string" /> <MetaInfo text="required" />
598596
- The name of the Vectorize index to query.
599-
- `--vector` <Type text="array" /> <MetaInfo text="required" />
600-
- Vector against which the Vectorize index is queried.
597+
- `--vector` <Type text="array" /> <MetaInfo text="optional" />
598+
- Vector against which the Vectorize index is queried. Either this or the `vector-id` param must be provided.
599+
- `--vector-id` <Type text="string" /> <MetaInfo text="optional" />
600+
- 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.
601601
- `--top-k` <Type text="number" /> <MetaInfo text="optional" />
602602
- The number of vectors to query (default: `5`).
603603
- `--return-values` <Type text="boolean" /> <MetaInfo text="optional" />

0 commit comments

Comments
 (0)