pref0 + Haystack

Add preference learning to Haystack pipelines. pref0 extracts user preferences and injects them into your Haystack components.

Quick start

python
from haystack import Pipeline
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
import requests

PREF0_API = "https://api.pref0.com"
PREF0_KEY = "pref0_sk_..."

def get_preferences(user_id: str) -> str:
    res = requests.get(
        f"{PREF0_API}/v1/profiles/{user_id}",
        headers={"Authorization": f"Bearer {PREF0_KEY}"},
    )
    prefs = res.json().get("preferences", [])
    return "\n".join(
        f"- {p['key']}: {p['value']}"
        for p in prefs if p["confidence"] >= 0.5
    )

learned = get_preferences("user_abc123")

pipe = Pipeline()
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o"))

messages = [
    ChatMessage.from_system(
        f"You are a helpful assistant.\n\nLearned preferences:\n{learned}"
    ),
    ChatMessage.from_user("Help me set up a new project"),
]

result = pipe.run({"llm": {"messages": messages}})

Why use pref0 with Haystack

Pipeline integration

Add preferences as a system message in any Haystack pipeline. Works with chat and RAG pipelines.

Component-friendly

pref0 works alongside retrievers, rankers, and generators. No custom component needed.

Production-ready

Both Haystack and pref0 are designed for production. Scale your personalized pipelines with confidence.

Framework-agnostic preferences

Preferences extracted by pref0 work with any Haystack component or model provider.

Other integrations

Add preference learning to Haystack

Your users are already teaching your agent what they want. pref0 makes sure the lesson sticks.