Troubleshooting Phoenix Tracer for Langchain Retriever Spans
Hi all, I use phoenix for tracing a rag application based on a langchain chain:
tracer = OpenInferenceTracer(exporter=HttpExporter(endpoint="http://0.0.0.0:6006"))
LangChainInstrumentor(tracer).instrument()
chain = (
self.__prompt
| llm.bind(functions=[function], function_call={'name': f_name})
| parser
)
chain.invoke(input)
Usually such a chain also contains a retriever of type VectorStoreRetriever which you get from vectorstore.as_retriever() . Basically this is just an abstraction and a wrapper to the similarity_search() method of the VectorStore (if you call vectorstore.as_retriever().get_relevant_documents()it calls similarity_search() under the hood). For some reason I had to code this manually by simply running similarity_search() on a VectorStore object (not using Langchain's wrapper class) and to pass the output directly to the llm as part of the prompt. So it does actually the same thing (it retrieves the most similar documents) but without being of type VectorStoreRetriever . As a consequence, the tracing of the run works completely fine, but whereas the spans template, llm and output parser get detected, there is no span for the retriever. When I look into the source code I just noticed that the tracer object is looking for run_type to determine "retriever" span.
if run["run_type"] != "retriever":
returnThus, I assume that since I don't use this VectorStoreRetriever wrapper, this attribute is not set at all, so the tracer can't recognize the retrieval part (where I call similarity_search() ) as a retriever. My question: Does anybody know (i) if the tracer indeed looks for such an attribute to determine the span and its name (e.g. retriever)? (ii) if so, any ideas where to set this manually so that a specific part or function call gets traced as retriever? (iii) if I am completely wrong, any suggestions about how to get my retriever identified as such? Every comment is highly appreciated! 馃檹
