PromptHelperο
General prompt helper that can help deal with LLM context window token limitations.
At its core, it calculates available context size by starting with the context window size of an LLM and reserve token space for the prompt template, and the output.
It provides utility for βrepackingβ text chunks (retrieved from index) to maximally make use of the available context window (and thereby reducing the number of LLM calls needed), or truncating them so that they fit in a single LLM call.
- class llama_index.indices.prompt_helper.PromptHelper(context_window: int = 3900, num_output: int = 256, chunk_overlap_ratio: float = 0.1, chunk_size_limit: Optional[int] = None, tokenizer: Optional[Callable[[str], List]] = None, separator: str = ' ', max_input_size: Optional[int] = None, embedding_limit: Optional[int] = None, max_chunk_overlap: Optional[int] = None)ο
Prompt helper.
General prompt helper that can help deal with LLM context window token limitations.
At its core, it calculates available context size by starting with the context window size of an LLM and reserve token space for the prompt template, and the output.
It provides utility for βrepackingβ text chunks (retrieved from index) to maximally make use of the available context window (and thereby reducing the number of LLM calls needed), or truncating them so that they fit in a single LLM call.
- Parameters
context_window (int) β Context window for the LLM.
num_output (int) β Number of outputs for the LLM.
chunk_overlap_ratio (float) β Chunk overlap as a ratio of chunk size
chunk_size_limit (Optional[int]) β Maximum chunk size to use.
tokenizer (Optional[Callable[[str], List]]) β Tokenizer to use.
separator (str) β Separator for text splitter
max_input_size (int) β deprecated, now renamed to context_window
embedding_limit (int) β deprecated, now consolidated with chunk_size_limit
max_chunk_overlap (int) β deprecated, now configured via chunk_overlap_ratio
- classmethod from_llm_metadata(llm_metadata: LLMMetadata, chunk_overlap_ratio: float = 0.1, chunk_size_limit: Optional[int] = None, tokenizer: Optional[Callable[[str], List]] = None, separator: str = ' ', max_input_size: Optional[int] = None, embedding_limit: Optional[int] = None, max_chunk_overlap: Optional[int] = None) PromptHelper ο
Create from llm predictor.
This will autofill values like context_window and num_output.
- get_text_splitter_given_prompt(prompt: Prompt, num_chunks: int = 1, padding: int = 5) TokenTextSplitter ο
Get text splitter configured to maximally pack available context window, taking into account of given prompt, and desired number of chunks.