Skip to content
Merged
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
13 changes: 10 additions & 3 deletions integrations/langfuse/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -136,10 +143,10 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]
# Examples can print their output
"examples/**" = ["T201", "ANN"]
"example/**" = ["T201", "ANN"]
"examples/**" = ["T201", "ANN", "D"]
"example/**" = ["T201", "ANN", "D"]
"tests/**" = ["T201"]

[tool.coverage.run]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class LangfuseConnector:
"""
LangfuseConnector connects Haystack LLM framework with [Langfuse](https://langfuse.com) in order to enable the

tracing of operations and data flow within various components of a pipeline.

To use LangfuseConnector, add it to your pipeline without connecting it to any other components.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def get_data(self) -> dict[str, Any]:
return self._data

def get_correlation_data_for_logs(self) -> dict[str, Any]:
"""Return correlation data for log enrichment."""
return {}


Expand Down Expand Up @@ -234,9 +235,11 @@ def handle(self, span: LangfuseSpan, component_type: str | None) -> None:

@classmethod
def from_dict(cls, data: dict[str, Any]) -> "SpanHandler":
"""Deserialize a SpanHandler from a dictionary."""
return default_from_dict(cls, data)

def to_dict(self) -> dict[str, Any]:
"""Serialize this SpanHandler to a dictionary."""
return default_to_dict(self)


Expand Down Expand Up @@ -273,6 +276,7 @@ class DefaultSpanHandler(SpanHandler):
"""DefaultSpanHandler provides the default Langfuse tracing behavior for Haystack."""

def create_span(self, context: SpanContext) -> LangfuseSpan:
"""Create a Langfuse span based on the given context."""
if self.tracer is None:
message = (
"Tracer is not initialized. "
Expand Down Expand Up @@ -343,6 +347,7 @@ def create_span(self, context: SpanContext) -> LangfuseSpan:
return LangfuseSpan(self.tracer.start_as_current_span(name=context.name))

def handle(self, span: LangfuseSpan, component_type: str | None) -> None:
"""Process and enrich a span after component execution."""
# If the span is at the pipeline level, we add input and output keys to the span
at_pipeline_level = span.get_data().get(_PIPELINE_INPUT_KEY) is not None
if at_pipeline_level:
Expand Down Expand Up @@ -456,6 +461,7 @@ def __init__(
def trace(
self, operation_name: str, tags: dict[str, Any] | None = None, parent_span: Span | None = None
) -> Iterator[Span]:
"""Create and manage a tracing span as a context manager."""
tags = tags or {}
span_name = tags.get(_COMPONENT_NAME_KEY, operation_name)
component_type = tags.get(_COMPONENT_TYPE_KEY)
Expand Down Expand Up @@ -543,6 +549,7 @@ def trace(
self.flush()

def flush(self) -> None:
"""Flush all pending spans to Langfuse."""
self._tracer.flush()

def current_span(self) -> Span | None:
Expand All @@ -558,13 +565,15 @@ def current_span(self) -> Span | None:
def get_trace_url(self) -> str:
"""
Return the URL to the tracing data.

:return: The URL to the tracing data.
"""
return self._tracer.get_trace_url() or ""

def get_trace_id(self) -> str:
"""
Return the trace ID.

:return: The trace ID.
"""
return self._tracer.get_current_trace_id() or ""
9 changes: 8 additions & 1 deletion integrations/lara/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -149,7 +156,7 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]

[tool.coverage.run]
source = ["haystack_integrations"]
Expand Down
9 changes: 8 additions & 1 deletion integrations/llama_cpp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -142,7 +149,7 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]
# Examples can print their output
"examples/**" = ["T201"]
"tests/**" = ["T201"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ def __init__(
model_clip_path: str | None = None,
) -> None:
"""
Initialize LlamaCppChatGenerator.

:param model: The path of a quantized model for text generation, for example, "zephyr-7b-beta.Q4_0.gguf".
If the model path is also specified in the `model_kwargs`, this parameter will be ignored.

:param n_ctx: The number of tokens in the context. When set to 0, the context will be taken from the model.
:param n_batch: Prompt processing maximum batch size.
:param model_kwargs: Dictionary containing keyword arguments used to initialize the LLM for text generation.
Expand Down Expand Up @@ -274,6 +277,7 @@ def __init__(
self._inference_lock = asyncio.Lock()

def warm_up(self) -> None:
"""Load and initialize the llama.cpp model."""
if self._model is not None:
return

Expand Down Expand Up @@ -462,6 +466,7 @@ def _handle_streaming_response(
) -> dict[str, list[ChatMessage]]:
"""
Take streaming responses from llama.cpp, convert to Haystack StreamingChunk objects, stream them,

and finally convert them to a ChatMessage.

:param response_stream: The streaming responses from llama.cpp.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ def __init__(
generation_kwargs: dict[str, Any] | None = None,
) -> None:
"""
Initialize LlamaCppGenerator.

:param model: The path of a quantized model for text generation, for example, "zephyr-7b-beta.Q4_0.gguf".
If the model path is also specified in the `model_kwargs`, this parameter will be ignored.

:param n_ctx: The number of tokens in the context. When set to 0, the context will be taken from the model.
:param n_batch: Prompt processing maximum batch size.
:param model_kwargs: Dictionary containing keyword arguments used to initialize the LLM for text generation.
Expand Down Expand Up @@ -69,6 +72,7 @@ def __init__(
self.model: Llama | None = None

def warm_up(self) -> None:
"""Load and initialize the llama.cpp model."""
if self.model is None:
self.model = Llama(**self.model_kwargs)

Expand Down
9 changes: 8 additions & 1 deletion integrations/llama_stack/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -137,7 +144,7 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN", "E501", "F841"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN", "E501", "F841"]
# Examples can print their output and don't need type annotations
"examples/**/*" = ["T201", "ANN"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class LlamaStackChatGenerator(OpenAIChatGenerator):
"""
Enables text generation using Llama Stack framework.

Llama Stack Server supports multiple inference providers, including Ollama, Together,
and vLLM and other cloud providers.
For a complete list of inference providers, see [Llama Stack docs](https://llama-stack.readthedocs.io/en/latest/providers/inference/index.html).
Expand Down Expand Up @@ -70,8 +71,10 @@ def __init__(
http_client_kwargs: dict[str, Any] | None = None,
) -> None:
"""
Creates an instance of LlamaStackChatGenerator. To use this chat generator,
you need to setup Llama Stack Server with an inference provider and have a model available.
Creates an instance of LlamaStackChatGenerator.

To use this chat generator, you need to setup Llama Stack Server with an inference provider and have a model
available.

:param model:
The name of the model to use for chat completion.
Expand Down
11 changes: 9 additions & 2 deletions integrations/mcp/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -153,8 +160,8 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"examples/**/*" = ["T201", "E501", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]
"examples/**/*" = ["T201", "E501", "ANN", "D"]

[tool.coverage.run]
source = ["haystack_integrations"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ def run_background(
self, coro_factory: Callable[[asyncio.Event], Coroutine[Any, Any, Any]], timeout: float | None = None
) -> tuple[concurrent.futures.Future[Any], asyncio.Event]:
"""
Schedule `coro_factory` to run in the executor's event loop **without** blocking the
caller thread.
Schedule `coro_factory` to run in the executor's event loop **without** blocking the caller thread.

The factory receives an :class:`asyncio.Event` that can be used to cooperatively shut
the coroutine down. The method returns **both** the concurrent future (to observe
Expand Down Expand Up @@ -1292,7 +1291,8 @@ def __del__(self) -> None:


class _MCPClientSessionManager:
"""Runs an MCPClient connect/close inside the AsyncExecutor's event loop.
"""
Runs an MCPClient connect/close inside the AsyncExecutor's event loop.

Life-cycle:
1. Create the worker to schedule a long-running coroutine in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def _deserialize_state_config(config: dict[str, dict[str, Any]] | None) -> dict[

class MCPToolset(Toolset):
"""
A Toolset that connects to an MCP (Model Context Protocol) server and provides
access to its tools.
A Toolset that connects to an MCP (Model Context Protocol) server and provides access to its tools.

MCPToolset dynamically discovers and loads all tools from any MCP-compliant server,
supporting both network-based streaming connections (Streamable HTTP, SSE) and local
Expand Down Expand Up @@ -289,7 +288,8 @@ def __init__(
self._warmup_called = True

def warm_up(self) -> None:
"""Connect and load tools when eager_connect is turned off.
"""
Connect and load tools when eager_connect is turned off.

This method is automatically called by ``ToolInvoker.warm_up()`` and ``Pipeline.warm_up()``.
You can also call it directly before using the toolset to ensure all tool schemas
Expand Down
9 changes: 8 additions & 1 deletion integrations/meta_llama/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -133,7 +140,7 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]

[tool.coverage.run]
source = ["haystack_integrations"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class MetaLlamaChatGenerator(OpenAIChatGenerator):
"""
Enables text generation using Llama generative models.

For supported models, see [Llama API Docs](https://llama.developer.meta.com/docs/).

Users can pass any text generation parameters valid for the Llama Chat Completion API
Expand Down Expand Up @@ -76,8 +77,9 @@ def __init__(
tools: ToolsType | None = None,
) -> None:
"""
Creates an instance of LlamaChatGenerator. Unless specified otherwise in the `model`, this is for Llama's
`Llama-4-Scout-17B-16E-Instruct-FP8` model.
Creates an instance of LlamaChatGenerator.

Unless specified otherwise in the `model`, this is for Llama's `Llama-4-Scout-17B-16E-Instruct-FP8` model.

:param api_key:
The Llama API key.
Expand Down
9 changes: 8 additions & 1 deletion integrations/mistral/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ select = [
"ARG",
"B",
"C",
"D102", # Missing docstring in public method
"D103", # Missing docstring in public function
"D205", # 1 blank line required between summary line and description
"D209", # Closing triple quotes go to new line
"D213", # summary lines must be positioned on the second physical line of the docstring
"D417", # Missing argument descriptions in the docstring
"D419", # Docstring is empty
"DTZ",
"E",
"EM",
Expand Down Expand Up @@ -136,7 +143,7 @@ ban-relative-imports = "parents"

[tool.ruff.lint.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252", "ANN"]
"tests/**/*" = ["D", "PLR2004", "S101", "TID252", "ANN"]

[tool.coverage.run]
source = ["haystack_integrations"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
@component
class MistralOCRDocumentConverter:
"""
This component extracts text from documents using Mistral's OCR API, with optional structured
annotations for both individual image regions (bounding boxes) and full documents.
Extract text from documents using Mistral's OCR API with optional structured annotations.

Supports optional structured annotations for individual image regions (bounding boxes) and full documents.

Accepts document sources in various formats (str/Path for local files, ByteStream for in-memory data,
DocumentURLChunk for document URLs, ImageURLChunk for image URLs, or FileChunk for Mistral file IDs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class MistralDocumentEmbedder(OpenAIDocumentEmbedder):
"""
A component for computing Document embeddings using Mistral models.

The embedding of each Document is stored in the `embedding` field of the Document.

Usage example:
Expand Down
Loading
Loading