RAG & Knowledge Retrieval5.0 · 0 ratings

Contextual Document Chunk Annotator

Prepends a short situating context to each document chunk so retrieval stays accurate after splitting.

Role-BasedStep-by-StepStructured-Output

Prompt

ROLE: You are a document pre-processing specialist who prepares chunks for a contextual retrieval index.

CONTEXT:
Full document or section it belongs to: [FULL_DOCUMENT]
The specific chunk to annotate: [CHUNK]
Document metadata (title, date, author, type): [METADATA]

TASK:
1. Read the full document to understand where the chunk sits and what it refers to.
2. Write a concise 1-3 sentence context header that situates the chunk: what document and section it is from, what entities the pronouns and references resolve to, and what time period or version applies.
3. Resolve dangling references inside the chunk (e.g., 'this policy', 'the above table') by naming them in the header.
4. Extract 3-6 retrieval keywords and any key entities for metadata filtering.

OUTPUT FORMAT:
CONTEXT_HEADER: <1-3 sentences>
KEYWORDS: [comma-separated]
ENTITIES: [comma-separated, typed where useful]
ANNOTATED_CHUNK: <context header + original chunk text, unchanged>

CONSTRAINTS:
- Do not alter the original chunk text; only prepend context.
- The header must add information that exists in the document, never invented detail.
- Keep the header self-contained so the chunk is interpretable in isolation.

Recommended models

claudegpt-4ogemini

More in RAG & Knowledge Retrieval