ReferencePredictor
Use this component in retrieval augmented generation (RAG) pipelines to predict references for the generated answer.
This component is deprecated. It will continue to work in your existing pipelines. You can use LLM-generated references instead. For more information, see Enable References for Generated Answers.
Key Features
- Adds predicted references to generated answers, showing which source documents the answer is based on.
- Uses a cross-encoder model to compare similarity between answer sentences and document sentences.
- Supports a verifiability model to identify answers that may need verification.
- The default model (
cross-encoder/ms-marco-MiniLM-L-6-v2) only works for English data. - Adds a
_referencesmetadata field to each answer containing reference details.
Configuration
- Drag the
ReferencePredictorcomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the reference prediction model path or name. The default is
cross-encoder/ms-marco-MiniLM-L-6-v2.
- Set the reference prediction model path or name. The default is
- Go to the Advanced tab to configure
use_split_rules,extend_abbreviations,verifiability_model,batch_size, and other parameters.
Connections
ReferencePredictor accepts a list of GeneratedAnswer objects as input. Connect its answers input to the answers output of a Generator or another answer-producing component.
It outputs a list of GeneratedAnswer objects enriched with a _references metadata field. Connect its answers output to AnswerBuilder or to the pipeline Output component.
Usage Examples
Basic Configuration
reference_predictor:
type: deepset_cloud_custom_nodes.augmenters.reference_predictor.ReferencePredictor
init_parameters:
use_split_rules: true
extend_abbreviations: true
This is an example of a query pipeline in which ReferencePredictor sends answers with references to AnswerBuilder.
components:
reference_predictor:
type: deepset_cloud_custom_nodes.augmenters.reference_predictor.ReferencePredictor
init_parameters:
use_split_rules: true
extend_abbreviations: true
answer_builder:
type: haystack.components.builders.answer_builder.AnswerBuilder
init_parameters: {}
connections:
- sender: reference_predictor.answers
receiver: answer_builder.answers
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
answers | List[GeneratedAnswer] | The generated answers to which you want to add references. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
answers | List[GeneratedAnswer] | Generated answers with a metadata field _references added to each answer containing a list of references. Each reference contains: document_start_idx, document_end_idx, answer_start_idx, answer_end_idx, score, document_id, document_position, and label. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | cross-encoder/ms-marco-MiniLM-L-6-v2 | The name identifier of the model to use on Hugging Face Hub or the path to a local model folder. |
revision | Optional[str] | None | The revision of the model to use. |
max_seq_len | int | 512 | The maximum number of tokens that a sequence should be truncated to before inference. |
language | Language | en | The language of the data to generate references for. The language is needed to apply the right sentence splitting rules. |
device | Optional[ComponentDevice] | None | The device on which the model is loaded. If None, the default device is automatically selected. |
batch_size | int | 16 | The batch size to use for inference. |
answer_window_size | int | 1 | How many sentences of an answer should be packed into one span for inference. |
document_window_size | int | 3 | How many sentences of a document should be packed into one span for inference. |
token | Optional[Secret] | Secret.from_env_var('HF_API_TOKEN', strict=False) | The token to use as HTTP bearer authorization for remote files. |
function_to_apply | str | sigmoid | What activation function to use on top of the logits. Available: sigmoid, softmax, none. |
min_score_2_label_thresholds | Optional[Dict] | None | The minimum prediction score threshold for each corresponding label. |
label_2_score_map | Optional[Dict] | None | If using a model with a multi-label prediction head, pass in a dict mapping label names to a float value that will be used as the score. |
reference_threshold | Optional[int] | None | If using this component to generate references for answer spans, you can pass in a minimum score threshold. If no threshold is passed, the reference is chosen by picking the maximum score. |
default_class | str | not_grounded | A fallback class to use if the predicted score doesn't match any threshold. |
verifiability_model | Optional[str] | tstadel/answer-classification-setfit-v2-binary | The name identifier of the verifiability model to use on Hugging Face Hub or the path to a local model folder. |
verifiability_revision | Optional[str] | None | The revision of the verifiability model to use. |
verifiability_batch_size | int | 32 | The batch size to use for verifiability inference. |
needs_verification_classes | List[str] or None | None | The class names to use to determine if a sentence needs verification. Defaults to ["needs_verification"]. |
use_split_rules | bool | False | If True, additional rules for better splitting answers are applied to the sentence splitting tokenizer. |
extend_abbreviations | bool | False | If True, the abbreviations used by NLTK's PunktTokenizer are extended by a list of curated abbreviations if available. |
answer_stride | int | 1 | The stride size for the answer window. |
document_stride | int | 3 | The stride size for the document window. |
model_kwargs | Optional[Dict] | None | Additional keyword arguments for the model. |
verifiability_model_kwargs | Optional[Dict] | None | Additional keyword arguments for the verifiability model. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
answers | List[GeneratedAnswer] | Replies returned by the Generator. |
Related Information
Was this page helpful?