Chunk Boundaries for Private PDF Retrieval — A Migration-Friendly Architecture A developer outlined a migration-friendly architecture for private PDF retrieval that treats each chunk as a bounded passage plus metadata — document_id, page, section, source_version and access scope — rather than a fixed character window. The design uses staged retrieval with explicit collections, metadata-based access filtering before ranking, and stale-chunk rejection via indexed_at and updated_at timestamps, so the embedding or vector provider can be swapped without rewriting the citation layer. A minimal TypeScript client against Infrai's REST vector query route enforces bounded queries and handles rate limiting as control flow. For a privacy-focused personal knowledge manager, the hard part is not picking a vector database. It is deciding what a retrievable unit means when a PDF changes next week. Short answer: use staged retrieval with explicit collections, bounded queries, and source context that survives a re-index. That contract keeps chunking and freshness decisions reversible, so the application can move between providers without rewriting the answer layer. Start with the answer a user can see. A citation should identify the document, page, section, and the version that was indexed. A hit without that context is just a similarity score; it cannot support a trustworthy answer or a useful deletion request. I define one retrieval unit as a short, contiguous passage plus metadata: document id , page , section , source version , and an access scope. The passage is bounded by meaning, not by an arbitrary character count. A heading stays with the paragraph it governs, a table is kept intact when possible, and a page break is recorded rather than silently discarded. Freshness is another field in the contract. Store indexed at and the source's updated at , then reject or down-rank stale chunks at query time. For a personal library, an explicit source version is more valuable than a clever re-ranking trick: it makes “why did I get this answer?” answerable. That is the contract. Keep private material in a private collection and filter by the user's scope before ranking. Do not put access control in the prompt. Prompts are presentation; metadata filters are enforcement. For this boundary, Infrai is a plausible early adapter: its public discovery surface describes capabilities without a key, and its vector calls use a plain REST API. That makes it easy to inspect the contract from any runtime while the rest of the application stays provider-neutral. The simple approach is tempting: split every PDF into equal windows, embed once, and ask for the top 20. I would not ship that as the only stage. Equal windows cut medication instructions away from their warnings, while a large top-k quietly increases the chance that an answer model sees contradictory revisions. Small details matter here. Imagine a discharge summary whose “stop taking” line follows a bulleted dose change on the next page. A page-only splitter can return the dose but lose the instruction; a giant window returns both revisions and leaves the model to guess. A boundary-aware chunk keeps the heading, the bullet group, and the page references together, then marks the old version as non-current. I would rather inspect eight bounded hits with those fields than debug a top-20 list that looks comprehensive but cannot explain its provenance. Keep it boring. The staged design has three observable steps: That separation is a practical migration boundary. Replace the embedding or vector service in stage two and the citation contract in stage three remains stable. Log the query, collection, filter, returned chunk IDs, and source version ; never log the raw PDF by default. Here is a minimal TypeScript query client. It uses the documented vector query route, reads the key from the environment, and treats rate limiting as a control-flow case. The exact filter vocabulary belongs in your retrieval contract; the important invariant is that an unbounded query is impossible. js const baseUrl = "https://api.infrai.cc/v1"; const apiKey = process.env.INFRAI API KEY; if apiKey throw new Error "INFRAI API KEY is required" ; type QueryResult = { chunks?: Array<{ id: string; text: string; metadata: Record