Citation Query Engine
- class llama_index.query_engine.citation_query_engine.CitationQueryEngine(retriever: BaseRetriever, response_synthesizer: Optional[BaseSynthesizer] = None, citation_chunk_size: int = 512, citation_chunk_overlap: int = 20, text_splitter: Optional[TextSplitter] = None, node_postprocessors: Optional[List[BaseNodePostprocessor]] = None, callback_manager: Optional[CallbackManager] = None)
Citation query engine.
- Parameters
retriever (BaseRetriever) – A retriever object.
response_synthesizer (Optional[BaseSynthesizer]) – A BaseSynthesizer object.
citation_chunk_size (int) – Size of citation chunks, default=512. Useful for controlling granularity of sources.
citation_chunk_overlap (int) – Overlap of citation nodes, default=20.
text_splitter (Optional[TextSplitterType]) – A text splitter for creating citation source nodes. Default is a SentenceSplitter.
callback_manager (Optional[CallbackManager]) – A callback manager.
- classmethod from_args(index: ~llama_index.indices.base.BaseIndex, response_synthesizer: ~typing.Optional[~llama_index.response_synthesizers.base.BaseSynthesizer] = None, citation_chunk_size: int = 512, citation_chunk_overlap: int = 20, text_splitter: ~typing.Optional[~llama_index.text_splitter.types.TextSplitter] = None, citation_qa_template: ~llama_index.prompts.base.BasePromptTemplate = PromptTemplate(metadata={'prompt_type': <PromptType.CUSTOM: 'custom'>}, template_vars=['context_str', 'query_str'], kwargs={}, output_parser=None, template="Please provide an answer based solely on the provided sources. When referencing information from a source, cite the appropriate source(s) using their corresponding numbers. Every answer should include at least one source citation. Only cite a source when you are explicitly referencing it. If none of the sources are helpful, you should indicate that. For example:\nSource 1:\nThe sky is red in the evening and blue in the morning.\nSource 2:\nWater is wet when the sky is red.\nQuery: When is water wet?\nAnswer: Water will be wet when the sky is red [2], which occurs in the evening [1].\nNow it's your turn. Below are several numbered sources of information:\n------\n{context_str}\n------\nQuery: {query_str}\nAnswer: "), citation_refine_template: ~llama_index.prompts.base.BasePromptTemplate = PromptTemplate(metadata={'prompt_type': <PromptType.CUSTOM: 'custom'>}, template_vars=['existing_answer', 'context_msg', 'query_str'], kwargs={}, output_parser=None, template="Please provide an answer based solely on the provided sources. When referencing information from a source, cite the appropriate source(s) using their corresponding numbers. Every answer should include at least one source citation. Only cite a source when you are explicitly referencing it. If none of the sources are helpful, you should indicate that. For example:\nSource 1:\nThe sky is red in the evening and blue in the morning.\nSource 2:\nWater is wet when the sky is red.\nQuery: When is water wet?\nAnswer: Water will be wet when the sky is red [2], which occurs in the evening [1].\nNow it's your turn. We have provided an existing answer: {existing_answer}Below are several numbered sources of information. Use them to refine the existing answer. If the provided sources are not helpful, you will repeat the existing answer.\nBegin refining!\n------\n{context_msg}\n------\nQuery: {query_str}\nAnswer: "), retriever: ~typing.Optional[~llama_index.indices.base_retriever.BaseRetriever] = None, node_postprocessors: ~typing.Optional[~typing.List[~llama_index.indices.postprocessor.types.BaseNodePostprocessor]] = None, response_mode: ~llama_index.response_synthesizers.type.ResponseMode = ResponseMode.COMPACT, use_async: bool = False, streaming: bool = False, **kwargs: ~typing.Any) CitationQueryEngine
Initialize a CitationQueryEngine object.”
- Parameters
index – (BastGPTIndex): index to use for querying
citation_chunk_size (int) – Size of citation chunks, default=512. Useful for controlling granularity of sources.
citation_chunk_overlap (int) – Overlap of citation nodes, default=20.
text_splitter (Optional[TextSplitter]) – A text splitter for creating citation source nodes. Default is a SentenceSplitter.
citation_qa_template (BasePromptTemplate) – Template for initial citation QA
citation_refine_template (BasePromptTemplate) – Template for citation refinement.
retriever (BaseRetriever) – A retriever object.
service_context (Optional[ServiceContext]) – A ServiceContext object.
node_postprocessors (Optional[List[BaseNodePostprocessor]]) – A list of node postprocessors.
verbose (bool) – Whether to print out debug info.
response_mode (ResponseMode) – A ResponseMode object.
use_async (bool) – Whether to use async.
streaming (bool) – Whether to use streaming.
optimizer (Optional[BaseTokenUsageOptimizer]) – A BaseTokenUsageOptimizer object.
- property retriever: BaseRetriever
Get the retriever object.