Skip to content

Commit ba67cf7

Browse files
authored
fix(cli): allow 32 MiB canonical knowledge index requests (#5679)
* fix(cli): allow 32 MiB canonical knowledge index requests The CLI capped one atomic index request at 10 MiB while the API accepts 32 MiB. With 3,072-dim embeddings this rejected books near 160 chunks, well below the 500-chunk cap. Match the API limit. * docs(cli): explain which index limit applies first
1 parent 8181a42 commit ba67cf7

3 files changed

Lines changed: 95 additions & 4 deletions

File tree

‎cli/commands/knowledge/indexing.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export interface IndexKnowledgeDocumentInput {
2828

2929
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3030
const MAX_CHUNKS = 500;
31-
const MAX_INDEX_BYTES = 10 * 1024 * 1024;
31+
// Mirrors the API's MAX_CANONICAL_INDEX_BYTES for one canonical index request.
32+
const MAX_INDEX_BYTES = 32 * 1024 * 1024;
3233

3334
interface KnowledgeIndexStatusItem {
3435
path: string;
@@ -295,7 +296,9 @@ export async function indexKnowledgeDocument(
295296
const payload = { expected_version_id: canonicalVersion.version_id, chunks, model };
296297
if (new TextEncoder().encode(JSON.stringify(payload)).byteLength > MAX_INDEX_BYTES) {
297298
throw new Error(
298-
"Knowledge index exceeds the 10 MiB atomic request limit. Split the source into smaller documents and retry.",
299+
`Knowledge index exceeds the ${
300+
MAX_INDEX_BYTES / 1024 / 1024
301+
} MiB atomic request limit. Split the source into smaller documents and retry.`,
299302
);
300303
}
301304
signal?.throwIfAborted();

‎docs/guides/cli-knowledge-ingestion.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ it ready. Failed-source results retain the canonical publication receipt so you
1919
can inspect the persisted document and retry. A source is successful only after
2020
its complete index commits on the destination branch.
2121

22-
Atomic indexing accepts at most 500 chunks and a 10 MiB request. Larger indexes
23-
fail with a useful error; split the source into smaller documents and retry.
22+
Atomic indexing accepts at most 500 chunks and a 32 MiB request. Which limit
23+
applies first depends on the embedding dimension. With the default 3,072-dimension
24+
model, the chunk cap applies first, at about 450 pages of prose. Wider embeddings
25+
reach the byte limit sooner. Larger indexes fail with a useful error; split the
26+
source into smaller documents and retry.
2427
Content is never truncated to fit the limit.
2528

2629
Ingest one uploaded file:

‎tests/integration/semantic-unit-boundary/cli/commands/knowledge/indexing.test.ts‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,91 @@ it("publishes more than one embedding batch as one complete canonical index with
670670
}
671671
});
672672

673+
function wideEmbedder(dimension: number): Embedding {
674+
const vector = Array(dimension).fill(0.012345678901234567);
675+
return {
676+
model: "veryfront-cloud/google/gemini-embedding-001",
677+
embed: async () => vector,
678+
embedMany: async (texts) => texts.map(() => vector),
679+
};
680+
}
681+
682+
it("commits a book-length index above 10 MiB as one atomic request", async () => {
683+
const root = await makeTempDir();
684+
try {
685+
const localPath = `${root}/topic.md`;
686+
await Deno.writeTextFile(localPath, "a".repeat(360_200));
687+
const currentPublished = await publishedForLocalPath(localPath);
688+
const commits: { path: string; chunks: number; bytes: number }[] = [];
689+
const client = createMockClient({
690+
post: async (path, payload) => {
691+
const json = JSON.stringify(payload);
692+
const body = JSON.parse(json);
693+
commits.push({
694+
path,
695+
chunks: body.chunks.length,
696+
bytes: new TextEncoder().encode(json).byteLength,
697+
});
698+
return {
699+
...currentPublished,
700+
indexed_chunk_count: body.chunks.length,
701+
model: body.model,
702+
};
703+
},
704+
});
705+
const receipt = await indexKnowledgeDocument({
706+
client,
707+
projectSlug: "project",
708+
branch: "preview",
709+
published: currentPublished,
710+
localPath,
711+
embedder: wideEmbedder(3072),
712+
});
713+
assertEquals(commits.length, 1);
714+
assertEquals(
715+
commits[0]?.path,
716+
"/projects/project/branches/preview/files/knowledge%2Ftopic.md/index",
717+
);
718+
assertEquals(commits[0]?.chunks, 200);
719+
assertEquals(commits[0]!.bytes > 10 * 1024 * 1024, true);
720+
assertEquals(receipt.indexed_chunk_count, 200);
721+
} finally {
722+
await Deno.remove(root, { recursive: true });
723+
}
724+
});
725+
726+
it("rejects an index above 32 MiB under the chunk cap without committing", async () => {
727+
const root = await makeTempDir();
728+
try {
729+
const localPath = `${root}/topic.md`;
730+
await Deno.writeTextFile(localPath, "a".repeat(810_200));
731+
const currentPublished = await publishedForLocalPath(localPath);
732+
let commits = 0;
733+
const client = createMockClient({
734+
post: async () => {
735+
commits++;
736+
return {};
737+
},
738+
});
739+
await assertRejects(
740+
() =>
741+
indexKnowledgeDocument({
742+
client,
743+
projectSlug: "project",
744+
branch: "preview",
745+
published: currentPublished,
746+
localPath,
747+
embedder: wideEmbedder(4096),
748+
}),
749+
Error,
750+
"32 MiB atomic request limit",
751+
);
752+
assertEquals(commits, 0);
753+
} finally {
754+
await Deno.remove(root, { recursive: true });
755+
}
756+
});
757+
673758
it("rejects noncanonical paths before reading source, embedding, or committing", async () => {
674759
let commits = 0;
675760
let embeddings = 0;

0 commit comments

Comments
 (0)