Contextual Retrieval
!!! info "📦 content package"
!!! note "Inspired by: Introducing Contextual Retrieval"
CreateChunkContext
CreateChunkContext generates a succinct context for a given chunk within the whole document content.
This context is intended to improve search retrieval of the chunk.
Parameters:
- wholeDocumentContent: The entire content of the document as a string.
- chunk: The specific chunk of the document for which context is to be generated.
- ollamaUrl: The URL for the Ollama service.
- contextualModel: The model used for generating the context.
- options: Additional options for the LLM (Language Model).
Returns:
- A string containing the succinct context for the chunk.
- An error if the context generation fails.
CreateChunkContextuse a default template for the prompt. If you want to use a custom template, you can useCreateChunkContextWithPromptTemplate.
CreateChunkContextWithPromptTemplate
CreateChunkContextWithPromptTemplate generates a contextual response based on a given prompt template and document content.
It interpolates the template with the provided document and chunk content, then uses an LLM to generate a response.
Parameters:
- promptTpl: A string template for the prompt.
- wholeDocumentContent: The content of the entire document.
- chunk: A Chunk struct containing a portion of the document content.
- ollamaUrl: The URL of the LLM service.
- contextualModel: The model to be used for generating the response.
- options: Options for the LLM query.
Returns:
- A string containing the generated response.
- An error if the process fails at any step.
Template example
promptTemplateForContext := `
<chunk>
{{.chunkContent}}
</chunk>
Generate a brief context of the above chunk to situate this chunk within the below document.
<document>
{{.wholeDocument}}
</document>
`
!!! note 👀 you will find a complete example in:
- [examples/59-jean-luc-picard-contextual-retrieval](https://github.com/parakeet-nest/parakeet/tree/main/examples/59-jean-luc-picard-contextual-retrieval)
Related Documents
You must use artifacts for
<citation_instructions>If the assistant's response is based on content returned by the web_search, drive_search, google_drive_search, or google_drive_fetch tool, the assistant must always appropriately cite its response. Here are the rules for good citations:
starProject
- **Description:** Multilingual Document Layout Parsing in a Single Vision-Language Model
Prompts
<img width="395" alt="prompts.chat" src="https://github.com/user-attachments/assets/e0d0e32d-d2ce-4459-9f37-e951d9f4f5de" />
Daily Agent Tasks Framework
**Your Daily System for Working with Claude and Codex**