LangChain ConversationalRetrieval with JSONloader – Langchain

by
Ali Hasan
chatgpt-api langchain llama-cpp-python openai-api py-langchain

The Problem:

You are working with a JSON file and have created a custom JSON loader for the ConversationalRetrievalChain in LangChain.
However, when you query the model with this loader, the responses are incorrect.
You need to determine if the issue lies with the JSON loader or the jq_scheme and adapt the code to generate the expected output.

The Solutions:

Solution 1: Changed default search result to a more manageable number

To fix the issue with incorrect answers from the conversational retrieval model, the following solution was implemented:

The default number of search results (top_k_docs_for_context) was increased from 4 to 10. This ensures that more relevant documents are returned for the LLM model to consider.

chain = ConversationalRetrievalChain.from_llm(
  llm=ChatOpenAI(model="gpt-3.5-turbo"),
  retriever=index.vectorstore.as_retriever(search_kwargs={"k": 10})
)

By providing a larger pool of relevant documents, the LLM model can generate more accurate and comprehensive answers.

Q&A

What is the difference between JSONLoader and TextLoader?

JSONLoader is used to load data from a JSON file, while TextLoader is used to load data from a text file.

How to set up jq_schema for JSONLoader?

jq_schema specifies the path to the data you want to load from the JSON file. For example, jq_schema=".reviews[]" will load all the reviews from a JSON file.

Why is the ConversationalRetrievalChain only returning 4 results?

By default, ConversationalRetrievalChain is set to return 4 results. You can change this by setting the top_k_docs_for_context parameter.

Video Explanation:

The following video, titled "Building Custom Tools and Agents with LangChain (gpt-3.5-turbo ...", provides additional insights and in-depth exploration related to the topics discussed in this post.

Play video

Exellent, but would love to see FOSS end-end using OpenAssitant, GPT4all, etc models. 11:50 · Go to channel · LangChain Retrieval QA Over ...