A block is already a chunk

区块本身就是切片

Adding embeddings to a content system usually starts with a chunking problem. AIBlog skipped that step, because its documents are already cut into typed blocks with stable ids — and four features fell out of one index.

Design note

Adding embeddings to a content system usually starts with a chunking problem. Documents are too long to embed whole, so they are cut into windows, and the windows do not line up with anything a reader would recognise. AIBlog skipped that step, because its documents are already cut.

The unit

A body is a stream of typed blocks, each a paragraph, a list, a quote, a table or a figure, each with a stable id. That is the unit retrieval wants: a coherent span with a meaning of its own and an address. A block is the chunk. A search hit can name the page and the block, and a link can land on the block.

What the ids buy

The change summary already says which blocks a revision altered. On publish, only those blocks are re-embedded. A page that had one paragraph reworded costs one vector, not thirty. The composer's reconciliation step, which keeps ids stable across regeneration, was built for the editor and the change summary; it turned out to be the mechanism embeddings needed too.

No new database

Vectors live on Firestore documents with a declared vector index, one per block plus one per page, and are queried with the store's own nearest-neighbour search. For a site of hundreds of pages that is a few thousand small documents. A dedicated vector store would be another adapter behind the same interface if a client ever needed one; none has.

Four features from one index

  • related pages at the foot of an article, from the page-level vectors
  • cross-lingual search, so an English query finds a body written in Chinese, fused in behind the keyword index when keywords return little
  • composer references: when a client pastes a report about a programme, the pages that already mention that programme are shown to the model for terminology and links, and only for that; facts must still trace to the pasted material
  • the visitor question box, answering from excerpts with block-level citations

The order is the order of value. Related pages replaced a guess. Cross-lingual search closed the one gap the bigram index could not. References improved consistency without weakening the fidelity check. The question box was the last and the only one that needed guardrails, because it is the only one a visitor can trigger.

Offline

A fake embeddings adapter returns deterministic vectors, so the integration tests exercise the whole path under the emulator with no network. The site also runs with no embeddings service at all, on the keyword index alone, and gains the four features the day a key is added and the reindex call is made.