I’m relatively new to Langchain and am seeking some assistance.
Overview of My Project
I’m creating an AI assistant for a movie theater application referred to as CinemaHub. This theater features two screening rooms (Room X and Room Y) where films are shown twice each day: once in the afternoon and once in the evening, across specific date ranges.
The assistant’s role is to provide users with details about movies, including pricing, showtimes, seat availability, and age restrictions. I aim for it to eventually manage bookings and cancellations, but at this moment, the primary retrieval functionality isn’t operating correctly.
Current Implementation
At present, I’m utilizing two distinct pipelines that are connected together:
query_pipeline = pipeline(
model=mistral_llm,
tokenizer=tok,
task="text-generation",
temperature=0.0,
do_sample=False,
repetition_penalty=1.1,
return_full_text=False,
max_new_tokens=800,
)
query_llm = HuggingFacePipeline(pipeline=query_pipeline)
answer_pipeline = pipeline(
model=mistral_llm,
tokenizer=tok,
task="text-generation",
do_sample=True,
repetition_penalty=1.1,
return_full_text=False,
max_new_tokens=4000,
)
answer_llm = HuggingFacePipeline(pipeline=answer_pipeline)
Following this, I have established my chain:
DOC_TEMPLATE = PromptTemplate.from_template(template="{page_content}")
def merge_docs(documents, doc_template=DOC_TEMPLATE, separator="\n\n"):
formatted_docs = [format_document(doc, doc_template) for doc in documents]
return separator.join(formatted_docs)
chat_memory = ConversationBufferMemory(
return_messages=True, output_key="response", input_key="query"
)
memory_loaded = RunnablePassthrough.assign(
history=RunnableLambda(chat_memory.load_memory_variables) | itemgetter("history"),
)
rephrased_query = {
"rephrased_query": {
"query": lambda x: x["query"],
"history": lambda x: get_buffer_string(x["history"]),
}
| REPHRASE_PROMPT
| query_llm,
}
fetched_docs = {
"documents": itemgetter("rephrased_query") | doc_retriever,
"query": lambda x: x["rephrased_query"],
}
final_prompt_inputs = {
"context": lambda x: merge_docs(x["documents"]),
"query": itemgetter("query"),
}
final_response = {
"response": final_prompt_inputs | RESPONSE_PROMPT | answer_llm,
"query": itemgetter("query"),
"context": final_prompt_inputs["context"]
}
full_chain = memory_loaded | rephrased_query | fetched_docs | final_response
My Data Format
I have generated a JSON file that includes 21 movies structured as follows:
[
{
"title": "Avatar: The Way of Water",
"tagline": "Return to the world of Pandora",
"synopsis": "Set more than a decade after the events of the first film, Avatar: The Way of Water begins to tell the story of the Sully family...",
"actors": ["Sam Worthington", "Zoe Saldana", "Sigourney Weaver"],
"category": "Sci-Fi",
"duration": "3h 12min",
"showDates": {
"from": "2024-07-01",
"to": "2024-07-15"
},
"matinee": {
"startTime": "15:30",
"cost": 12,
"discounted_cost": 8
},
"evening": {
"startTime": "20:30",
"cost": 18,
"discounted_cost": 12
},
"standardSeats": {
"open": 180,
"booked": 95
},
"accessibleSeats": {
"open": 12,
"booked": 3
},
"allSeats": {
"open": 192,
"booked": 98
},
"theater": "Room X",
"rating": "PG-13"
}
]
Key Challenges
- It seems the retriever isn’t retrieving the most pertinent documents.
- Occasionally, Mistral appears to be disoriented by lengthy prompts.
- I am unsure whether to use similarity search, MMR, or another method.
I transform each film into a textual summary and employ RecursiveCharacterTextSplitter with a chunk size of 1200. The embeddings used are from ChromaDB with BAAI/bge-large-en-v1.5.
Can anyone provide insights into what might be going wrong? Any advice would be greatly appreciated!