Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs-website/reference/haystack-api/builders_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ print(res)
# 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 27, 'completion_tokens': 681, 'total_tokens':
# 708}})]}}

messages = [system_message, ChatMessage.from_user("What's the weather forecast for {{location}} in the next
{{day_count}} days?")]
messages = [system_message, ChatMessage.from_user("What's the weather forecast for {{location}} in the next {{day_count}} days?")]

res = pipe.run(data={"prompt_builder": {"template_variables": {"location": location, "day_count": "5"},
"template": messages}})
Expand Down
8 changes: 4 additions & 4 deletions docs-website/reference/haystack-api/connectors_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ result = service_connector.run(
)
print(result)

# {'service_response': ChatMessage(_role=<ChatRole.USER: 'user'>, _content=[TextContent(text=
# '{"searchParameters": {"q": "Why was Sam Altman ousted from OpenAI?",
# "type": "search", "engine": "google"}, "answerBox": {"snippet": "Concerns over AI safety and OpenAI's role
# in protecting were at the center of Altman's brief ouster from the company."...
# >> {'service_response': ChatMessage(_role=<ChatRole.ASSISTANT: 'assistant'>, _content=[TextContent(text=
# >> '{"searchParameters": {"q": "Why was Sam Altman ousted from OpenAI?",
# >> "type": "search", "engine": "google"}, "answerBox": {"snippet": "Concerns over AI safety and OpenAI's role
# >> in protecting were at the center of Altman's brief ouster from the company."...
```

#### __init__
Expand Down
7 changes: 4 additions & 3 deletions docs-website/reference/haystack-api/converters_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ It can attach metadata to the resulting documents.
### Usage example

```python
from datetime import datetime
from haystack.components.converters.csv import CSVToDocument
converter = CSVToDocument()
results = converter.run(sources=["sample.csv"], meta={"date_added": datetime.now().isoformat()})
Expand Down Expand Up @@ -1268,7 +1269,7 @@ from haystack import Document
from haystack.components.converters import OutputAdapter

adapter = OutputAdapter(template="{{ documents[0].content }}", output_type=str)
documents = [Document(content="Test content"]
documents = [Document(content="Test content")]
result = adapter.run(documents=documents)

assert result["output"] == "Test content"
Expand Down Expand Up @@ -1836,7 +1837,6 @@ Converts text files to documents.

### XLSXToDocument

````
Converts XLSX (Excel) files into Documents.

Supports reading data from specific sheets or all sheets in the Excel file. If all sheets are read, a Document is
Expand All @@ -1846,13 +1846,14 @@ created for each sheet. The content of the Document is the table which can be sa

```python
from haystack.components.converters.xlsx import XLSXToDocument
from datetime import datetime

converter = XLSXToDocument()
results = converter.run(sources=["sample.xlsx"], meta={"date_added": datetime.now().isoformat()})
documents = results["documents"]
print(documents[0].content)
# ",A,B
````
```

1,col_a,col_b
2,1.5,test
Expand Down
2 changes: 1 addition & 1 deletion docs-website/reference/haystack-api/evaluators_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ print(result["score"])
# 0.5
print(result["results"])
# [{'statements': ['Python is a high-level general-purpose programming language.',
'Python was created by George Lucas.'], 'statement_scores': [1, 0], 'score': 0.5}]
# 'Python was created by George Lucas.'], 'statement_scores': [1, 0], 'score': 0.5}]
```

#### __init__
Expand Down
26 changes: 13 additions & 13 deletions docs-website/reference/haystack-api/extractors_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,19 @@ extractor = LLMMetadataExtractor(
)

extractor.run(documents=docs)
>> {'documents': [
Document(id=.., content: 'deepset was founded in 2018 in Berlin, and is known for its Haystack framework',
meta: {'entities': [{'entity': 'deepset', 'entity_type': 'company'}, {'entity': 'Berlin', 'entity_type': 'city'},
{'entity': 'Haystack', 'entity_type': 'product'}]}),
Document(id=.., content: 'Hugging Face is a company that was founded in New York, USA and is known for its Transformers library',
meta: {'entities': [
{'entity': 'Hugging Face', 'entity_type': 'company'}, {'entity': 'New York', 'entity_type': 'city'},
{'entity': 'USA', 'entity_type': 'country'}, {'entity': 'Transformers', 'entity_type': 'product'}
]})
]
'failed_documents': []
}
>>
# >> {'documents': [
# >> Document(id=.., content: 'deepset was founded in 2018 in Berlin, and is known for its Haystack framework',
# >> meta: {'entities': [{'entity': 'deepset', 'entity_type': 'company'}, {'entity': 'Berlin', 'entity_type': 'city'},
# >> {'entity': 'Haystack', 'entity_type': 'product'}]}),
# >> Document(id=.., content: 'Hugging Face is a company that was founded in New York, USA and is known for its Transformers library',
# >> meta: {'entities': [
# >> {'entity': 'Hugging Face', 'entity_type': 'company'}, {'entity': 'New York', 'entity_type': 'city'},
# >> {'entity': 'USA', 'entity_type': 'country'}, {'entity': 'Transformers', 'entity_type': 'product'}
# >> ]})
# >> ]
# >> 'failed_documents': []
# >> }
# >>>>
```

#### __init__
Expand Down
16 changes: 9 additions & 7 deletions docs-website/reference/haystack-api/generators_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ print(result)

#### With paid inference endpoints

````python
```python
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
Expand All @@ -760,9 +760,11 @@ generator = HuggingFaceAPIChatGenerator(api_type="inference_endpoints",

result = generator.run(messages)
print(result)
```

#### With self-hosted text generation inference


```python
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
from haystack.dataclasses import ChatMessage
Expand All @@ -775,7 +777,7 @@ generator = HuggingFaceAPIChatGenerator(api_type="text_generation_inference",

result = generator.run(messages)
print(result)
````
```

#### __init__

Expand Down Expand Up @@ -2136,11 +2138,11 @@ client = OpenAIGenerator()
response = client.run("What's Natural Language Processing? Be brief.")
print(response)

>> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
>> the interaction between computers and human language. It involves enabling computers to understand, interpret,
>> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model':
>> 'gpt-5-mini', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
>> 'completion_tokens': 49, 'total_tokens': 65}}]}
# >> {'replies': ['Natural Language Processing (NLP) is a branch of artificial intelligence that focuses on
# >> the interaction between computers and human language. It involves enabling computers to understand, interpret,
# >> and respond to natural human language in a way that is both meaningful and useful.'], 'meta': [{'model':
# >> 'gpt-5-mini', 'index': 0, 'finish_reason': 'stop', 'usage': {'prompt_tokens': 16,
# >> 'completion_tokens': 49, 'total_tokens': 65}}]}
```

#### __init__
Expand Down
14 changes: 5 additions & 9 deletions docs-website/reference/haystack-api/joiners_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ messages = [ChatMessage.from_system("You are a helpful, respectful and honest as
ChatMessage.from_user(query)]

pipe = Pipeline()
pipe.add_component("llm_1", OpenAIChatGenerator()
pipe.add_component("llm_2", OpenAIChatGenerator()
pipe.add_component("llm_1", OpenAIChatGenerator())
pipe.add_component("llm_2", OpenAIChatGenerator())
pipe.add_component("aba", AnswerBuilder())
pipe.add_component("abb", AnswerBuilder())
pipe.add_component("joiner", AnswerJoiner())
Expand Down Expand Up @@ -198,9 +198,8 @@ result = pipe.run(

print(json.loads(result["validator"]["validated"][0].text))


>> {'first_name': 'Peter', 'last_name': 'Parker', 'nationality': 'American', 'name': 'Spider-Man', 'occupation':
>> 'Superhero', 'age': 23, 'location': 'New York City'}
# >> {'first_name': 'Peter', 'last_name': 'Parker', 'nationality': 'American', 'name': 'Spider-Man', 'occupation':
# >> 'Superhero', 'age': 23, 'location': 'New York City'}
```

Note that `BranchJoiner` can manage only one data type at a time. In this case, `BranchJoiner` is created for
Expand Down Expand Up @@ -529,9 +528,6 @@ from haystack.components.joiners import StringJoiner
from haystack.components.builders import PromptBuilder
from haystack.core.pipeline import Pipeline

from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage

string_1 = "What's Natural Language Processing?"
string_2 = "What is life?"

Expand All @@ -545,7 +541,7 @@ pipeline.connect("prompt_builder_2.prompt", "string_joiner.strings")

print(pipeline.run(data={"prompt_builder_1": {"query": string_1}, "prompt_builder_2": {"query": string_2}}))

>> {"string_joiner": {"strings": ["Builder 1: What's Natural Language Processing?", "Builder 2: What is life?"]}}
# >> {"string_joiner": {"strings": ["Builder 1: What's Natural Language Processing?", "Builder 2: What is life?"]}}
```

#### run
Expand Down
24 changes: 11 additions & 13 deletions docs-website/reference/haystack-api/preprocessors_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,13 @@ from haystack.components.preprocessors import HierarchicalDocumentSplitter
doc = Document(content="This is a simple test document")
splitter = HierarchicalDocumentSplitter(block_sizes={3, 2}, split_overlap=0, split_by="word")
splitter.run([doc])
>> {'documents': [Document(id=3f7..., content: 'This is a simple test document', meta: {'block_size': 0, 'parent_id': None, 'children_ids': ['5ff..', '8dc..'], 'level': 0}),
>> Document(id=5ff.., content: 'This is a ', meta: {'block_size': 3, 'parent_id': '3f7..', 'children_ids': ['f19..', '52c..'], 'level': 1, 'source_id': '3f7..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
>> Document(id=8dc.., content: 'simple test document', meta: {'block_size': 3, 'parent_id': '3f7..', 'children_ids': ['39d..', 'e23..'], 'level': 1, 'source_id': '3f7..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 10}),
>> Document(id=f19.., content: 'This is ', meta: {'block_size': 2, 'parent_id': '5ff..', 'children_ids': [], 'level': 2, 'source_id': '5ff..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
>> Document(id=52c.., content: 'a ', meta: {'block_size': 2, 'parent_id': '5ff..', 'children_ids': [], 'level': 2, 'source_id': '5ff..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 8}),
>> Document(id=39d.., content: 'simple test ', meta: {'block_size': 2, 'parent_id': '8dc..', 'children_ids': [], 'level': 2, 'source_id': '8dc..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
>> Document(id=e23.., content: 'document', meta: {'block_size': 2, 'parent_id': '8dc..', 'children_ids': [], 'level': 2, 'source_id': '8dc..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 12})]}
# >> {'documents': [Document(id=3f7..., content: 'This is a simple test document', meta: {'block_size': 0, 'parent_id': None, 'children_ids': ['5ff..', '8dc..'], 'level': 0}),
# >> Document(id=5ff.., content: 'This is a ', meta: {'block_size': 3, 'parent_id': '3f7..', 'children_ids': ['f19..', '52c..'], 'level': 1, 'source_id': '3f7..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
# >> Document(id=8dc.., content: 'simple test document', meta: {'block_size': 3, 'parent_id': '3f7..', 'children_ids': ['39d..', 'e23..'], 'level': 1, 'source_id': '3f7..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 10}),
# >> Document(id=f19.., content: 'This is ', meta: {'block_size': 2, 'parent_id': '5ff..', 'children_ids': [], 'level': 2, 'source_id': '5ff..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
# >> Document(id=52c.., content: 'a ', meta: {'block_size': 2, 'parent_id': '5ff..', 'children_ids': [], 'level': 2, 'source_id': '5ff..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 8}),
# >> Document(id=39d.., content: 'simple test ', meta: {'block_size': 2, 'parent_id': '8dc..', 'children_ids': [], 'level': 2, 'source_id': '8dc..', 'page_number': 1, 'split_id': 0, 'split_idx_start': 0}),
# >> Document(id=e23.., content: 'document', meta: {'block_size': 2, 'parent_id': '8dc..', 'children_ids': [], 'level': 2, 'source_id': '8dc..', 'page_number': 1, 'split_id': 1, 'split_idx_start': 12})]}
```

#### __init__
Expand Down Expand Up @@ -861,12 +861,10 @@ AI technology is widely used throughout industry, government, and science. Some
doc = Document(content=text)
doc_chunks = chunker.run([doc])
print(doc_chunks["documents"])
>[
>Document(id=..., content: 'Artificial intelligence (AI) - Introduction\n\n', meta: {'original_id': '...', 'split_id': 0, 'split_idx_start': 0, '_split_overlap': []})
>Document(id=..., content: 'AI, in its broadest sense, is intelligence exhibited by machines, particularly computer systems.\n', meta: {'original_id': '...', 'split_id': 1, 'split_idx_start': 45, '_split_overlap': []})
>Document(id=..., content: 'AI technology is widely used throughout industry, government, and science.', meta: {'original_id': '...', 'split_id': 2, 'split_idx_start': 142, '_split_overlap': []})
>Document(id=..., content: ' Some high-profile applications include advanced web search engines; recommendation systems; interac...', meta: {'original_id': '...', 'split_id': 3, 'split_idx_start': 216, '_split_overlap': []})
>]
# >>[Document(id=..., content: 'Artificial intelligence (AI) - Introduction\n\n', meta: {'original_id': '...', 'split_id': 0, 'split_idx_start': 0, '_split_overlap': []})
# >>Document(id=..., content: 'AI, in its broadest sense, is intelligence exhibited by machines, particularly computer systems.\n', meta: {'original_id': '...', 'split_id': 1, 'split_idx_start': 45, '_split_overlap': []})
# >>Document(id=..., content: 'AI technology is widely used throughout industry, government, and science.', meta: {'original_id': '...', 'split_id': 2, 'split_idx_start': 142, '_split_overlap': []})
# >>Document(id=..., content: ' Some high-profile applications include advanced web search engines; recommendation systems; interac...', meta: {'original_id': '...', 'split_id': 3, 'split_idx_start': 216, '_split_overlap': []})]
```

#### __init__
Expand Down
4 changes: 2 additions & 2 deletions docs-website/reference/haystack-api/rankers_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ result = reranker.run(query="What is the capital of France?", documents=docs)

ranked_docs = result["documents"]
print(ranked_docs)
>> {'documents': [Document(id=..., content: 'the capital of France is Paris', score: 0.9979767),
>> Document(id=..., content: 'the capital of Germany is Berlin', score: 0.13982213)]}
# >> {'documents': [Document(id=..., content: 'the capital of France is Paris', score: 0.9979767),
# >> Document(id=..., content: 'the capital of Germany is Berlin', score: 0.13982213)]}
```

#### __init__
Expand Down
31 changes: 10 additions & 21 deletions docs-website/reference/haystack-api/routers_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,12 @@ Categorize files or byte streams according to their MIME types.

### LLMMessagesRouter

````
Routes Chat Messages to different connections using a generative Language Model to perform classification.

This component can be used with general-purpose LLMs and with specialized LLMs for moderation like Llama Guard.

### Usage example

```python
from haystack.components.generators.chat import HuggingFaceAPIChatGenerator
from haystack.components.routers.llm_messages_router import LLMMessagesRouter
Expand All @@ -530,32 +530,21 @@ from haystack.dataclasses import ChatMessage
# initialize a Chat Generator with a generative model for moderation
chat_generator = HuggingFaceAPIChatGenerator(
api_type="serverless_inference_api",
api_params={"model": "meta-llama/Llama-Guard-4-12B", "provider": "groq"},
api_params={"model": "openai/gpt-oss-safeguard-20b"},
)

router = LLMMessagesRouter(chat_generator=chat_generator,
output_names=["unsafe", "safe"],
output_patterns=["unsafe", "safe"])

router = LLMMessagesRouter(
chat_generator=chat_generator, output_names=["unsafe", "safe"], output_patterns=["unsafe", "safe"]
)

print(router.run([ChatMessage.from_user("How to rob a bank?")]))

# {
# 'chat_generator_text': 'unsafe
````

S2',
\# 'unsafe': \[
\# ChatMessage(
\# \_role=\<ChatRole.USER: 'user'>,
\# \_content=[TextContent(text='How to rob a bank?')],
\# \_name=None,
\# \_meta={}
\# )
\# \]
\# }
\`\`\`
# >> {'chat_generator_text': 'I’m sorry, but I can’t help with that.',
# >> 'unmatched': [ChatMessage(_role=<ChatRole.USER: 'user'>,
# >> _content=[TextContent(text='How to rob a bank?')], _name=None, _meta={})]
# }

```
#### __init__

```python
Expand Down
60 changes: 30 additions & 30 deletions docs-website/reference/haystack-api/tools_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,20 @@ def get_weather(
tool = create_tool_from_function(get_weather)

print(tool)
>>> Tool(name='get_weather', description='A simple function to get the current weather for a location.',
>>> parameters={
>>> 'type': 'object',
>>> 'properties': {
>>> 'city': {'type': 'string', 'description': 'the city for which to get the weather', 'default': 'Munich'},
>>> 'unit': {
>>> 'type': 'string',
>>> 'enum': ['Celsius', 'Fahrenheit'],
>>> 'description': 'the unit for the temperature',
>>> 'default': 'Celsius',
>>> },
>>> }
>>> },
>>> function=<function get_weather at 0x7f7b3a8a9b80>)
# >> Tool(name='get_weather', description='A simple function to get the current weather for a location.',
# >> parameters={
# >> 'type': 'object',
# >> 'properties': {
# >> 'city': {'type': 'string', 'description': 'the city for which to get the weather', 'default': 'Munich'},
# >> 'unit': {
# >> 'type': 'string',
# >> 'enum': ['Celsius', 'Fahrenheit'],
# >> 'description': 'the unit for the temperature',
# >> 'default': 'Celsius',
# >> },
# >> }
# >> },
# >> function=<function get_weather at 0x7f7b3a8a9b80>)
```

**Parameters:**
Expand Down Expand Up @@ -339,20 +339,20 @@ def get_weather(
return f"Weather report for {city}: 20 {unit}, sunny"

print(get_weather)
>>> Tool(name='get_weather', description='A simple function to get the current weather for a location.',
>>> parameters={
>>> 'type': 'object',
>>> 'properties': {
>>> 'city': {'type': 'string', 'description': 'the city for which to get the weather', 'default': 'Munich'},
>>> 'unit': {
>>> 'type': 'string',
>>> 'enum': ['Celsius', 'Fahrenheit'],
>>> 'description': 'the unit for the temperature',
>>> 'default': 'Celsius',
>>> },
>>> }
>>> },
>>> function=<function get_weather at 0x7f7b3a8a9b80>)
# >> Tool(name='get_weather', description='A simple function to get the current weather for a location.',
# >> parameters={
# >> 'type': 'object',
# >> 'properties': {
# >> 'city': {'type': 'string', 'description': 'the city for which to get the weather', 'default': 'Munich'},
# >> 'unit': {
# >> 'type': 'string',
# >> 'enum': ['Celsius', 'Fahrenheit'],
# >> 'description': 'the unit for the temperature',
# >> 'default': 'Celsius',
# >> },
# >> }
# >> },
# >> function=<function get_weather at 0x7f7b3a8a9b80>)
```

**Parameters:**
Expand Down Expand Up @@ -662,8 +662,8 @@ from haystack.tools import Tool, SearchableToolset

# Create a catalog of tools
catalog = [
Tool(name="get_weather", description="Get weather for a city", ...),
Tool(name="search_web", description="Search the web", ...),
Tool(name="get_weather", description="Get weather for a city"),
Tool(name="search_web", description="Search the web"),
# ... 100s more tools
]
toolset = SearchableToolset(catalog=catalog)
Expand Down
Loading
Loading