Add preference learning to Haystack pipelines. pref0 extracts user preferences and injects them into your Haystack components.
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}})Add preferences as a system message in any Haystack pipeline. Works with chat and RAG pipelines.
pref0 works alongside retrievers, rankers, and generators. No custom component needed.
Both Haystack and pref0 are designed for production. Scale your personalized pipelines with confidence.
Preferences extracted by pref0 work with any Haystack component or model provider.
Your users are already teaching your agent what they want. pref0 makes sure the lesson sticks.