Add UserID and Feedback when using LlamaIndex Integration #1434
-
I am using Langfuse with a llamaindex integration. Is there a way I can add a user-id to my traces. Additionally how can I add user feedback to my traces if I have that user-id |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, for user_id and other trace-level attributes, have a look here: https://langfuse.com/docs/integrations/llama-index/get-started#set-trace-params You can capture user feedback as a score, follow this tutorial to create a trace via the python sdk to then get a llamaindex callback handler: https://langfuse.com/docs/integrations/llama-index/get-started#interoperability-with-langfuse-sdks from llama_index.core import Settings
from llama_index.core.callbacks import CallbackManager
from langfuse import Langfuse
# Instantiate a Langfuse Client
langfuse = Langfuse()
# Instantiate a new LlamaIndexCallbackHandler and register it in the LlamaIndex Settings
langfuse_callback_handler = LlamaIndexCallbackHandler()
Settings.callback_manager = CallbackManager([langfuse_callback_handler])
def my_func():
# Create a new trace on your main execution path
root_trace = langfuse.trace(name="trace-name", user_id="user_id)
# Set the root trace, subsequent LlamaIndex observations will be nested under root
langfuse_callback_handler.set_root(root_trace)
# Your LlamaIndex code here
# Reset root, subsequent LlamaIndex observations will now use the default grouping and trace creation
langfuse_callback_handler.set_root(None)
# add score instantly
trace = langfuse.score(...)
# get trace id to add score later
trace_id = trace.id
# add score to previous trace id
langfuse.score(
trace_id=trace_id,
name="quality",
value=1,
comment="Factually correct",
) |
Beta Was this translation helpful? Give feedback.
Yes, for user_id and other trace-level attributes, have a look here: https://langfuse.com/docs/integrations/llama-index/get-started#set-trace-params
You can capture user feedback as a score, follow this tutorial to create a trace via the python sdk to then get a llamaindex callback handler: https://langfuse.com/docs/integrations/llama-index/get-started#interoperability-with-langfuse-sdks
The trace can then be used as a reference to add scores (https://langfuse.com/docs/scores/custom).
If you use this integration, also add the user_id and other params to the trace directly.