Musterby Elitery
Integrations

Exa

Trace Exa AI search operations in Muster via the @observe(as_type="retriever") decorator.

Exa is an AI search engine. Wrap its calls with Muster's @observe(as_type="retriever") decorator to capture queries, results, and latencies as retriever spans.

Setup

%pip install langfuse exa-py
import os

os.environ["LANGFUSE_PUBLIC_KEY"] = "pk-lf-..."
os.environ["LANGFUSE_SECRET_KEY"] = "sk-lf-..."
os.environ["LANGFUSE_BASE_URL"] = "https://app.getmuster.io"
os.environ["EXA_API_KEY"] = "..."
from exa_py import Exa
from langfuse import get_client

exa = Exa(api_key=os.environ["EXA_API_KEY"])
langfuse = get_client()
from langfuse import observe

@observe(as_type="retriever")
def search_with_exa(query: str, num_results: int = 5):
    return exa.search_and_contents(query, num_results=num_results, text=True)

search_with_exa("What is Muster?")

Combined: search + summarise

from langfuse.openai import OpenAI

@observe()
def search_and_summarize(query: str):
    results = search_with_exa(query)
    context = "\n".join([f"{r.title}: {r.text}" for r in results.results])

    client = OpenAI()
    resp = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": f"Summarise:\n{context}"}],
    )
    return resp.choices[0].message.content

Exa search trace in Muster

See also