Find answers from the community

Updated last year

Trace Queries

Hello, anyone know how to print out intermediate steps and times ? Trace: query |_query -> 6.765974 seconds |_retrieve -> 0.404373 seconds |_embedding -> 0.394931 seconds |_synthesize -> 6.361441 seconds |_llm -> 6.334911 seconds

like this one
W
z
2 comments
Found something similar to your need @zhozho

Plain Text
from llama_index.callbacks import CallbackManager, LlamaDebugHandler, CBEventType

# Set up the LlamaDebugHandler
llama_debug = LlamaDebugHandler(print_trace_on_end=True)
callback_manager = CallbackManager([llama_debug])

# Create a ServiceContext with the CallbackManager
service_context = ServiceContext.from_defaults(callback_manager=callback_manager)

# Trigger the callback with a query
index = VectorStoreIndex.from_documents(docs, service_context=service_context)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")

https://gpt-index.readthedocs.io/en/latest/examples/callbacks/LlamaDebugHandler.html
thank you, ur a legend.πŸ’―
Add a reply
Sign up and join the conversation on Discord