Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Parent run not found when using Callbacks with langchain EnsembleRetriever #1818

Closed
nathan-vo810 opened this issue Apr 23, 2024 · 6 comments

Comments

@nathan-vo810
Copy link

nathan-vo810 commented Apr 23, 2024

Describe the bug

When trying to pass Langfuse callbacks into EnsembleRetriever, Exception was raised.

Screenshot 2024-04-23 at 19 28 32

To reproduce

from langfuse.callback import CallbackHandler
from langchain.retrievers import BM25Retriever, EnsembleRetriever

question = ""
    
vector_db_client_provider = PGVectorClient()
vectorstore = vector_db_client_provider.get_client("user")

docs = vectorstore.similarity_search(query=question, k=1)
bm25_retriever = BM25Retriever.from_documents(documents=docs)
vector_retriever = vectorstore.as_retriever()

ensemble_retriever = EnsembleRetriever(retrievers=[vector_retriever, bm25_retriever], weights=[0.5, 0.5])

relevant_docs = ensemble_retriever.get_relevant_documents(question, callbacks=[CallbackHandler()])

Additional information

No response

@marcklingen
Copy link
Member

Thanks for sharing, do you use this retriever standalone or within a larger chain/agent? We designed the hadnler to work best when being passed to invoke/call/... methods which then also include the EnsembleRetriever. I'll try to look into solution on how to fix this issue though as this seems to be a very valid use case

@nathan-vo810
Copy link
Author

nathan-vo810 commented Apr 23, 2024

I use that as a standalone for my RAG pipeline. Rather than incorporating with Langchain, I built separated components and finally link them together.

An additional note:

  • When I was using the ConversationRetrievalChain, Langfuse callbacks worked perfectly (show traces for both retrievers).
  • But when coding a function and use observe, traces do not appear for the retrievers (only the function trace)

@marcklingen
Copy link
Member

I use that as a standalone for my RAG pipeline. Rather than incorporating with Langchain, I built separated components and finally link them together.

Thanks for confirming

An additional note:

  • When I was using the ConversationRetrievalChain, Langfuse callbacks worked perfectly (show traces for both retrievers).
  • But when coding a function and use observe, traces do not appear for the retrievers (only the function trace)

This is expected, unless you pass a callback handler to the langchain pieces of your function as shown here: https://langfuse.com/docs/sdk/python/decorators#langchain

@nathan-vo810
Copy link
Author

Ah yes, I did pass langfuse_context.get_current_langchain_handler() to my EnsembleRetriever. But the result is as above exception.

Thanks for providing such a great tool and I look forward to the solution!

@marcklingen
Copy link
Member

Ah yes, I did pass langfuse_context.get_current_langchain_handler() to my EnsembleRetriever. But the result is as above exception.

Thanks for providing such a great tool and I look forward to the solution!

👍 awesome, I was worried that the docs were not clear enough on how this works

probably decorating a function that wraps the get_relevant_documents and just passing all kwargs is the best workaround until this is fixed. thereby you at least can track the inputs/outputs/timings of this within your larger context.

@marcklingen
Copy link
Member

Merging this into #1927 to collect all instances of this error

@marcklingen marcklingen closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants