Skip to content

Commit fc08e1d

Browse files
committed
Vectorize: Update Best Practices with a section on improving write Throughput
1 parent 68cdaf5 commit fc08e1d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ let matches = await env.TUTORIAL_INDEX.query(queryVector, {
9494
});
9595
```
9696

97+
## Improve Write Throughput
98+
99+
One way to reduce the time to make updates visible in queries is to batch more vectors into fewer requests. This is important for write-heavy workloads. To see how many vectors you can write in a single request, please refer to the [Limits](/vectorize/platform/limits/) page.
100+
101+
Vectorize writes changes immeditely to a write ahead log for durability. To make these writes visible for reads, an asynchronous job needs to read the current index files from R2, create an updated index, write the new index files back to R2, and commit the change. To keep the overhead of writes low and improve write throughput, Vectorize will combine multiple changes together into a single batch. It sets the maximum size of a batch to 200,000 total vectors or to 1,000 individual updates, whichever limit it hits first.
102+
103+
For example, let's say we have 250,000 vectors we would like to insert into our index. We decide to insert them one at a time, calling the insert API 250,000 times. Vectorize will only process 1000 vectors in each job, and will need to work through 250 total jobs. This could take at least an hour to do.
104+
105+
The better approach is to batch our updates. For example, we can split our 250,000 vectors into 100 files, where each file has 2,500 vectors. We would call the insert HTTP API 100 times. Vectorize would update the index in only 2 or 3 jobs. All 250,000 vectors will visible in queries within minutes.
106+
97107
## Examples
98108

99109
### Workers API

0 commit comments

Comments
 (0)