broadfield-dev commited on
Commit
ba1a5aa
·
verified ·
1 Parent(s): 62a35cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -14
app.py CHANGED
@@ -162,25 +162,50 @@ def search_memory():
162
  return jsonify({"error": "No query provided"}), 400
163
 
164
  try:
165
- # FIX: "dict cannot be converted to PyString" means
166
- # the first argument must be the query string, not a dict.
167
- results = db.find(query=query)
 
 
 
 
168
 
169
- formatted_results = []
170
- for hit in results:
171
- print(hit)
172
- if isinstance(hit, dict):
173
- text = hit.get('text') or hit.get('content') or "No text"
174
- else:
175
- text = getattr(hit, 'text', getattr(hit, 'content', str(hit)))
176
-
177
- formatted_results.append({
178
- "text": text
 
 
 
 
 
179
  })
180
 
181
- return jsonify({"success": True, "results": formatted_results})
 
 
182
  except Exception as e:
183
  return jsonify({"error": str(e)}), 500
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  if __name__ == '__main__':
186
  app.run(host='0.0.0.0', port=7860)
 
162
  return jsonify({"error": "No query provided"}), 400
163
 
164
  try:
165
+ # 1. Refined Request
166
+ search_req = {
167
+ "query": query,
168
+ "top_k": 10, # Ask for more...
169
+ "snippet_chars": 150, # ...but get smaller chunks
170
+ "no_sketch": False # Use the sketch track for speed
171
+ }
172
 
173
+ response = db.find(query, **search_req)
174
+
175
+ # 2. Refined Parsing (The Anti-Junk Filter)
176
+ clean_results = []
177
+ for hit in response.hits:
178
+ # Filter low relevance
179
+ if hit.score < 0.65:
180
+ continue
181
+
182
+ clean_results.append({
183
+ "title": hit.title or "Untitled Memory",
184
+ "snippet": hit.snippet, # The highlighted text
185
+ "full_text": hit.text, # Available on click
186
+ "date": hit.timestamp, # Context!
187
+ "score": f"{hit.score:.2f}"
188
  })
189
 
190
+ #return jsonify(clean_results)
191
+
192
+ return jsonify({"success": True, "results": clean_results})
193
  except Exception as e:
194
  return jsonify({"error": str(e)}), 500
195
 
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
  if __name__ == '__main__':
211
  app.run(host='0.0.0.0', port=7860)