Skip to content

Commit c78de27

Browse files
authored
Merge branch 'main' into jinja2-set-vars-incorrect
2 parents 492073e + 5546169 commit c78de27

File tree

64 files changed

+500
-1058
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+500
-1058
lines changed

docs-website/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@
4545
},
4646
"engines": {
4747
"node": ">=18.0"
48-
}
48+
},
49+
"packageManager": "npm"
4950
}

docs-website/reference/haystack-api/agents_api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/agents-api"
77

88
<a id="agent"></a>
99

10-
# Module agent
10+
## Module agent
1111

1212
<a id="agent.Agent"></a>
1313

14-
## Agent
14+
### Agent
1515

1616
A Haystack component that implements a tool-using agent with provider-agnostic chat model support.
1717

@@ -221,11 +221,11 @@ A dictionary with the following keys:
221221

222222
<a id="state/state"></a>
223223

224-
# Module state/state
224+
## Module state/state
225225

226226
<a id="state/state.State"></a>
227227

228-
## State
228+
### State
229229

230230
State is a container for storing shared information during the execution of an Agent and its tools.
231231

docs-website/reference/haystack-api/audio_api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/audio-api"
77

88
<a id="whisper_local"></a>
99

10-
# Module whisper\_local
10+
## Module whisper\_local
1111

1212
<a id="whisper_local.LocalWhisperTranscriber"></a>
1313

14-
## LocalWhisperTranscriber
14+
### LocalWhisperTranscriber
1515

1616
Transcribes audio files using OpenAI's Whisper model on your local machine.
1717

@@ -144,11 +144,11 @@ A list of Documents, one for each file.
144144

145145
<a id="whisper_remote"></a>
146146

147-
# Module whisper\_remote
147+
## Module whisper\_remote
148148

149149
<a id="whisper_remote.RemoteWhisperTranscriber"></a>
150150

151-
## RemoteWhisperTranscriber
151+
### RemoteWhisperTranscriber
152152

153153
Transcribes audio files using the OpenAI's Whisper API.
154154

docs-website/reference/haystack-api/builders_api.md

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/builders-api"
77

88
<a id="answer_builder"></a>
99

10-
# Module answer\_builder
10+
## Module answer\_builder
1111

1212
<a id="answer_builder.AnswerBuilder"></a>
1313

14-
## AnswerBuilder
14+
### AnswerBuilder
1515

1616
Converts a query and Generator replies into a `GeneratedAnswer` object.
1717

@@ -22,12 +22,47 @@ AnswerBuilder works with both non-chat and chat Generators.
2222

2323
### Usage example
2424

25+
26+
### Usage example with documents and reference pattern
27+
2528
```python
2629
from haystack.components.builders import AnswerBuilder
2730

2831
builder = AnswerBuilder(pattern="Answer: (.*)")
2932
builder.run(query="What's the answer?", replies=["This is an argument. Answer: This is the answer."])
3033
```
34+
```python
35+
from haystack import Document
36+
from haystack.components.builders import AnswerBuilder
37+
38+
replies = ["The capital of France is Paris [2]."]
39+
40+
docs = [
41+
Document(content="Berlin is the capital of Germany."),
42+
Document(content="Paris is the capital of France."),
43+
Document(content="Rome is the capital of Italy."),
44+
]
45+
46+
builder = AnswerBuilder(reference_pattern="\[(\d+)\]", return_only_referenced_documents=False)
47+
result = builder.run(query="What is the capital of France?", replies=replies, documents=docs)["answers"][0]
48+
49+
print(f"Answer: {result.data}")
50+
print("References:")
51+
for doc in result.documents:
52+
if doc.meta["referenced"]:
53+
print(f"[{doc.meta['source_index']}] {doc.content}")
54+
print("Other sources:")
55+
for doc in result.documents:
56+
if not doc.meta["referenced"]:
57+
print(f"[{doc.meta['source_index']}] {doc.content}")
58+
59+
# Answer: The capital of France is Paris
60+
# References:
61+
# [2] Paris is the capital of France.
62+
# Other sources:
63+
# [1] Berlin is the capital of Germany.
64+
# [3] Rome is the capital of Italy.
65+
```
3166

3267
<a id="answer_builder.AnswerBuilder.__init__"></a>
3368

@@ -36,7 +71,9 @@ builder.run(query="What's the answer?", replies=["This is an argument. Answer: T
3671
```python
3772
def __init__(pattern: Optional[str] = None,
3873
reference_pattern: Optional[str] = None,
39-
last_message_only: bool = False)
74+
last_message_only: bool = False,
75+
*,
76+
return_only_referenced_documents: bool = True)
4077
```
4178

4279
Creates an instance of the AnswerBuilder component.
@@ -52,11 +89,16 @@ Examples:
5289
`[^\n]+$` finds "this is an answer" in a string "this is an argument.\nthis is an answer".
5390
`Answer: (.*)` finds "this is an answer" in a string "this is an argument. Answer: this is an answer".
5491
- `reference_pattern`: The regular expression pattern used for parsing the document references.
55-
If not specified, no parsing is done, and all documents are referenced.
92+
If not specified, no parsing is done, and all documents are returned.
5693
References need to be specified as indices of the input documents and start at [1].
5794
Example: `\[(\d+)\]` finds "1" in a string "this is an answer[1]".
95+
If this parameter is provided, documents metadata will contain a "referenced" key with a boolean value.
5896
- `last_message_only`: If False (default value), all messages are used as the answer.
5997
If True, only the last message is used as the answer.
98+
- `return_only_referenced_documents`: To be used in conjunction with `reference_pattern`.
99+
If True (default value), only the documents that were actually referenced in `replies` are returned.
100+
If False, all documents are returned.
101+
If `reference_pattern` is not provided, this parameter has no effect, and all documents are returned.
60102

61103
<a id="answer_builder.AnswerBuilder.run"></a>
62104

@@ -80,9 +122,12 @@ Turns the output of a Generator into `GeneratedAnswer` objects using regular exp
80122
- `replies`: The output of the Generator. Can be a list of strings or a list of `ChatMessage` objects.
81123
- `meta`: The metadata returned by the Generator. If not specified, the generated answer will contain no metadata.
82124
- `documents`: The documents used as the Generator inputs. If specified, they are added to
83-
the`GeneratedAnswer` objects.
84-
If both `documents` and `reference_pattern` are specified, the documents referenced in the
85-
Generator output are extracted from the input documents and added to the `GeneratedAnswer` objects.
125+
the `GeneratedAnswer` objects.
126+
Each Document.meta includes a "source_index" key, representing its 1-based position in the input list.
127+
When `reference_pattern` is provided:
128+
- "referenced" key is added to the Document.meta, indicating if the document was referenced in the output.
129+
- `return_only_referenced_documents` init parameter controls if all or only referenced documents are
130+
returned.
86131
- `pattern`: The regular expression pattern to extract the answer text from the Generator.
87132
If not specified, the entire response is used as the answer.
88133
The regular expression can have one capture group at most.
@@ -93,7 +138,7 @@ is used as the answer. If no capture group is present, the whole match is used a
93138
`Answer: (.*)` finds "this is an answer" in a string
94139
"this is an argument. Answer: this is an answer".
95140
- `reference_pattern`: The regular expression pattern used for parsing the document references.
96-
If not specified, no parsing is done, and all documents are referenced.
141+
If not specified, no parsing is done, and all documents are returned.
97142
References need to be specified as indices of the input documents and start at [1].
98143
Example: `\[(\d+)\]` finds "1" in a string "this is an answer[1]".
99144

@@ -104,11 +149,11 @@ A dictionary with the following keys:
104149

105150
<a id="prompt_builder"></a>
106151

107-
# Module prompt\_builder
152+
## Module prompt\_builder
108153

109154
<a id="prompt_builder.PromptBuilder"></a>
110155

111-
## PromptBuilder
156+
### PromptBuilder
112157

113158
Renders a prompt filling in any variables so that it can send it to a Generator.
114159

@@ -306,11 +351,11 @@ A dictionary with the following keys:
306351

307352
<a id="chat_prompt_builder"></a>
308353

309-
# Module chat\_prompt\_builder
354+
## Module chat\_prompt\_builder
310355

311356
<a id="chat_prompt_builder.ChatPromptBuilder"></a>
312357

313-
## ChatPromptBuilder
358+
### ChatPromptBuilder
314359

315360
Renders a chat prompt from a template using Jinja2 syntax.
316361

docs-website/reference/haystack-api/cachings_api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/caching-api"
77

88
<a id="cache_checker"></a>
99

10-
# Module cache\_checker
10+
## Module cache\_checker
1111

1212
<a id="cache_checker.CacheChecker"></a>
1313

14-
## CacheChecker
14+
### CacheChecker
1515

1616
Checks for the presence of documents in a Document Store based on a specified field in each document's metadata.
1717

docs-website/reference/haystack-api/classifiers_api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/classifiers-api"
77

88
<a id="document_language_classifier"></a>
99

10-
# Module document\_language\_classifier
10+
## Module document\_language\_classifier
1111

1212
<a id="document_language_classifier.DocumentLanguageClassifier"></a>
1313

14-
## DocumentLanguageClassifier
14+
### DocumentLanguageClassifier
1515

1616
Classifies the language of each document and adds it to its metadata.
1717

@@ -93,11 +93,11 @@ A dictionary with the following key:
9393

9494
<a id="zero_shot_document_classifier"></a>
9595

96-
# Module zero\_shot\_document\_classifier
96+
## Module zero\_shot\_document\_classifier
9797

9898
<a id="zero_shot_document_classifier.TransformersZeroShotDocumentClassifier"></a>
9999

100-
## TransformersZeroShotDocumentClassifier
100+
### TransformersZeroShotDocumentClassifier
101101

102102
Performs zero-shot classification of documents based on given labels and adds the predicted label to their metadata.
103103

docs-website/reference/haystack-api/connectors_api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ slug: "/connectors-api"
77

88
<a id="openapi_service"></a>
99

10-
# Module openapi\_service
10+
## Module openapi\_service
1111

1212
<a id="openapi_service.OpenAPIServiceConnector"></a>
1313

14-
## OpenAPIServiceConnector
14+
### OpenAPIServiceConnector
1515

1616
A component which connects the Haystack framework to OpenAPI services.
1717

@@ -148,11 +148,11 @@ The deserialized component.
148148

149149
<a id="openapi"></a>
150150

151-
# Module openapi
151+
## Module openapi
152152

153153
<a id="openapi.OpenAPIConnector"></a>
154154

155-
## OpenAPIConnector
155+
### OpenAPIConnector
156156

157157
OpenAPIConnector enables direct invocation of REST endpoints defined in an OpenAPI specification.
158158

0 commit comments

Comments
 (0)