Skip to main content

OpenTelemetry instrumentation for Haystack

Project description

Haystack OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the Haystack framework. It enables tracing and monitoring of applications built with Haystack.

Installation

  1. Install traceAI Haystack
pip install traceAI-haystack

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="haystack_app"
)

Configure Haystack Instrumentation

Instrument the Haystack client to enable telemetry collection. This step ensures that all interactions with the Haystack SDK are tracked and monitored.

from traceai_haystack import HaystackInstrumentor

HaystackInstrumentor().instrument(tracer_provider=trace_provider)

Create Haystack Components

from haystack import Document, Pipeline
from haystack.components.builders import PromptBuilder
from haystack.components.embedders import (
    SentenceTransformersDocumentEmbedder,
    SentenceTransformersTextEmbedder,
)
from haystack.components.generators import OpenAIGenerator
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack.document_stores.in_memory import InMemoryDocumentStore
from datasets import load_dataset

document_store = InMemoryDocumentStore()

dataset = load_dataset("bilgeyucel/seven-wonders", split="train")
docs = [Document(content=doc["content"], meta=doc["meta"]) for doc in dataset]

doc_embedder = SentenceTransformersDocumentEmbedder(
    model="sentence-transformers/all-MiniLM-L6-v2"
)
doc_embedder.warm_up()

docs_with_embeddings = doc_embedder.run(docs)
document_store.write_documents(docs_with_embeddings["documents"])

text_embedder = SentenceTransformersTextEmbedder(
    model="sentence-transformers/all-MiniLM-L6-v2"
)

retriever = InMemoryEmbeddingRetriever(document_store)

template = """
Given the following information, answer the question.

Context:
{% for document in documents %}
    {{ document.content }}
{% endfor %}

Question: {{question}}
Answer:
"""

prompt_builder = PromptBuilder(template=template)

generator = OpenAIGenerator(model="gpt-3.5-turbo")

basic_rag_pipeline = Pipeline()
basic_rag_pipeline.add_component("text_embedder", text_embedder)
basic_rag_pipeline.add_component("retriever", retriever)
basic_rag_pipeline.add_component("prompt_builder", prompt_builder)
basic_rag_pipeline.add_component("llm", generator)

basic_rag_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
basic_rag_pipeline.connect("retriever", "prompt_builder.documents")
basic_rag_pipeline.connect("prompt_builder", "llm")

question = "What does Rhodes Statue look like?"

response = basic_rag_pipeline.run(
    {"text_embedder": {"text": question}, "prompt_builder": {"question": question}}
)

print(response["llm"]["replies"][0])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traceai_haystack-0.1.7.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

traceai_haystack-0.1.7-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file traceai_haystack-0.1.7.tar.gz.

File metadata

  • Download URL: traceai_haystack-0.1.7.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_haystack-0.1.7.tar.gz
Algorithm Hash digest
SHA256 9a195977245bd6a17c71271d1fa4e130e2de0823c5676e4de068b770d2d50d64
MD5 88daca52b78cc562d82b6e1b5ef96b9a
BLAKE2b-256 359a54fe8e46fd00158ad5a24e782212887a68adf50efdc919fe123f2f1e7c7d

See more details on using hashes here.

File details

Details for the file traceai_haystack-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: traceai_haystack-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_haystack-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fa23a79bab28743e2a09cac120e84fabe6cdaf69939e1270d665f78be3a05751
MD5 555ef43f60ec55512b282f075d6ad142
BLAKE2b-256 3159aebd581d9e7b146d8a50db3224c534ff6fbb44842dd66249e0038449f247

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page