You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromlangchain.promptsimportPromptTemplateverbatim_prompt=PromptTemplate(
input_variables=["context", "question"],
template="""Below is the raw text:----------------{context}----------------Question: {question}Please return the exact matching text from the section above. Do not summarize, paraphrase, or alter the text in any way. Return the full excerpt verbatim."""
)
defget_conversational_chain(self):
model=ChatGoogleGenerativeAI(model="gemini-1.5-pro", temperature=0.0)
chain=load_qa_chain(
llm=model,
chain_type="stuff",
prompt=verbatim_prompt,
document_variable_name="context",
verbose=True,
)
returnchain
Description
What I’m doing:
I upload one or more PDFs, split them into 10000-token chunks, and build a FAISS index of those chunks.
I retrieve the top-k chunks with vector_store.similarity_search(…).
I feed them into LangChain’s “stuff” QA chain with a verbatim prompt template.
The problem:
Instead of spitting back the full chunk I asked for, Gemini still summarizes or cuts off the text midway. I need the entire verbatim excerpt, but every response is truncated (regardless of how large I set my chunks).
Question:
What am I missing? Is there a chain configuration, prompt format, or Gemini parameter that forces a full-text return instead of a summary/truncation? Or do I need to use a different chain type (e.g. map-reduce or refine) or a different model setting to get unabridged verbatim output?
Any pointers or sample code would be hugely appreciated...thanks!
System Info
Environment:
Python: 3.11
Flask: 3.0.3
LangChain: 0.2.6
langchain-community: 0.2.6
langchain-core: 0.2.10
langchain-text-splitters: 0.2.2
FAISS (faiss-cpu): 1.8.0.post1
PyPDF2: 3.0.1
google-generativeai: 0.8.4
google-ai-generativelanguage: 0.6.15
langchain-google-genai: (whatever version you have)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Example Code
Description
What I’m doing:
The problem:
Instead of spitting back the full chunk I asked for, Gemini still summarizes or cuts off the text midway. I need the entire verbatim excerpt, but every response is truncated (regardless of how large I set my chunks).
Question:
What am I missing? Is there a chain configuration, prompt format, or Gemini parameter that forces a full-text return instead of a summary/truncation? Or do I need to use a different chain type (e.g. map-reduce or refine) or a different model setting to get unabridged verbatim output?
Any pointers or sample code would be hugely appreciated...thanks!
System Info
Environment:
Beta Was this translation helpful? Give feedback.
All reactions