WaysAhead Global commited on
Commit
11ec7a5
·
verified ·
1 Parent(s): 319cec9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -190,26 +190,33 @@ load_or_create_faiss()
190
  @tool
191
  def retrieve_documents(query: str) -> str:
192
  """
193
- Retrieve a clean, text-only answer by matching documents using FAISS.
194
- Returns only the combined snippets (no source metadata).
 
 
 
 
 
 
 
 
195
  """
196
  if not vector_store:
197
- return "I'm sorry, the document system is currently unavailable."
198
-
199
- def clean(text):
200
- text = re.sub(r'\[([^\]]+)\]\((https?://[^\)]+)\)', r'\1', text)
201
- text = re.sub(r'https?://\S+', '', text)
202
- return text.strip()
203
 
204
  try:
205
- docs = vector_store.similarity_search(query, k=5)
206
- if not docs:
207
- return "No relevant documents found."
208
- combined = "\n\n".join(clean(d.page_content) for d in docs)
209
- return combined
 
 
 
 
210
  except Exception as e:
211
- logging.error(f"Document retrieval failed: {e}")
212
- return "There was an error retrieving documents."
213
  @tool
214
  def fetch_youtube_videos(query: str) -> list:
215
  """
 
190
  @tool
191
  def retrieve_documents(query: str) -> str:
192
  """
193
+ 🧠 Use this tool when the answer is likely found in a document, article, magazine, or written content.
194
+
195
+ 💡 Ideal for questions that involve:
196
+ - What someone said, did, or thinks
197
+ - Quotes, opinions, event mentions
198
+ - Details that would appear in a news article, magazine, or report
199
+
200
+ ❌ Do NOT use for email addresses or CRM-like participant info (use Zoho tool instead)
201
+
202
+ This tool uses a FAISS vector store and RetrievalQA to find the most relevant chunks and generate a context-based answer.
203
  """
204
  if not vector_store:
205
+ return "The document system is currently unavailable."
 
 
 
 
 
206
 
207
  try:
208
+ retriever = vector_store.as_retriever(search_kwargs={"k": 5})
209
+ qa = RetrievalQA.from_chain_type(
210
+ llm=ChatOpenAI(model="gpt-4", temperature=0),
211
+ retriever=retriever,
212
+ return_source_documents=False,
213
+ chain_type="stuff"
214
+ )
215
+ return qa.run(query)
216
+
217
  except Exception as e:
218
+ logging.error(f"Document QA error: {e}")
219
+ return "There was an error fetching the answer from documents."
220
  @tool
221
  def fetch_youtube_videos(query: str) -> list:
222
  """