Repository: truera/trulens
Issue: [BUG] Could not locate app.retriever.get_relevant_documents.rets[:].page_content.collect() in app/record.
Root cause: Documentation Deficiency

using this code 

def trulens_recorder(query_engine, app_id):
    """
    Get trulens recorder
    """
    openai = OpenAI(deployment_name="name of the model")

    qa_relevance = (
        Feedback(openai.relevance_with_cot_reasons, name="Answer Relevance")
        .on_input_output()
    )

    qs_relevance = (
        Feedback(openai.qs_relevance_with_cot_reasons, name = "Context Relevance")
        .on_input()
        .on(Select.RecordCalls.retriever.get_relevant_documents.rets[:].page_content.collect())
        .aggregate(np.mean)
    )

    grounded = Groundedness(groundedness_provider=openai)

    groundedness = (
        Feedback(grounded.groundedness_measure_with_cot_reasons, name="Groundedness")
        .on(Select.RecordCalls.retriever.get_relevant_documents.rets[:].page_content.collect())
        .on_output()
        .aggregate(grounded.grounded_statements_aggregator)
    )

    feedbacks = [qa_relevance, qs_relevance, groundedness]
    tru_recorder = TruChain(
        query_engine,
        app_id=app_id,
        feedbacks=feedbacks
    )
    return tru_recorder
    
    i'm currently using a retirval.qa chain and just use LCEL like
     RunnableAssign({"original_text": itemgetter("query")}) | retival_chain
     
     i faced the issue that it can't find the retriver key but when i remove the useage of LCEL and just use retival_chain ... it passed
     
     
     is there an issue when i'm using LCEL?

<!-- Answer -->
The issue you're encountering with not being able to locate `app.retriever.get_relevant_documents.rets[:].page_content.collect()` in `app/record` when using LCEL alongside your retrieval chain is due to the way LCEL (LangChain Evaluation and Logging) interacts with the retrieval chain. LCEL introduces an additional layer of abstraction that can modify how methods and properties are accessed, which is why the problem doesn't occur when you bypass LCEL and directly use the `retrieval_chain`.

This behavior stems from LCEL's design to instrument, log, and evaluate LangChain applications, which can interfere with direct method calls and property accesses. Direct interaction with the `retrieval_chain` avoids the modifications made by LCEL, allowing for unaltered access to methods and properties.

To further diagnose the issue, sharing the exact error message or exception you're receiving would be very helpful. This additional detail can aid in pinpointing the specific interaction causing the problem within the LCEL framework.


<!-- Dosu Comment Footer -->
<details>
<summary>

#### Details
</summary>

**Sources**
- [Could not locate app.get_relevant_documents.rets[:].page_content in app/record.](https://github.com/truera/trulens/issues/936)
- [trulens_eval/trulens_eval/tru_chain.py](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/tru_chain.py)
- [trulens_eval/examples/expositional/frameworks/langchain/langchain_retrieval_agent.ipynb](https://github.com/truera/trulens/blob/main/trulens_eval/examples/expositional/frameworks/langchain/langchain_retrieval_agent.ipynb)
- [trulens_eval/trulens_eval/utils/langchain.py](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/utils/langchain.py)
- [trulens_eval/examples/experimental/MultiQueryRetrievalLangchain.ipynb](https://github.com/truera/trulens/blob/main/trulens_eval/examples/experimental/MultiQueryRetrievalLangchain.ipynb)
- [docs/trulens_eval/tracking/instrumentation/langchain.ipynb](https://github.com/truera/trulens/blob/main/docs/trulens_eval/tracking/instrumentation/langchain.ipynb)
- [trulens_eval/examples/expositional/vector-dbs/pinecone/pinecone_evals_build_better_rags.ipynb](https://github.com/truera/trulens/blob/main/trulens_eval/examples/expositional/vector-dbs/pinecone/pinecone_evals_build_better_rags.ipynb)
- [trulens_eval/trulens_eval/database/exceptions.py](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/database/exceptions.py)
- [trulens_eval/trulens_eval/app.py](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/app.py)
- [trulens_eval/trulens_eval/schema/record.py](https://github.com/truera/trulens/blob/main/trulens_eval/trulens_eval/schema/record.py)

<br/>

**About Dosu**
This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
</details>

*To continue the conversation, mention @dosu.*


@yuvneshtruera  Do you have any recommended solution?
@joshreini1  can you help?

No issue with LCEL - but the structure can be different, leaving the context at a different location in your application then you're specifying with the feedback selector. Can you share your LCEL setup so we can help? @AraHema 

@joshreini1  something like that RunnableAssign({"original_text": itemgetter("query")}) | retival_chain
where retrival_chain is a RetrivalQA chain

Where the RetivalQA use a ensembler retriever 
And how i pass the context to the selector ..... as i mentioned above an example for the function i'm using for the trulens


Here's an example of how to work with the Langchain ensemble retriever. Let me know if this helps: https://github.com/truera/trulens/blob/main/trulens_eval/examples/expositional/frameworks/langchain/langchain_ensemble_retriever.ipynb