Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions search_knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,41 @@ def _smart_fallback(query: str, docs: list):
print()


def _prompt_feedback(query: str, found_any: bool):
"""Prompt user for search result feedback and log to data/search-feedback.jsonl."""
import datetime
try:
print("─── Search Feedback ───")
answer = input(f" Was this helpful? (y/n/c=comment/Enter=skip): ").strip().lower()
feedback_data = {
"query": query,
"found_results": found_any,
"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
}
if answer == "y":
feedback_data["feedback"] = "helpful"
elif answer == "n":
feedback_data["feedback"] = "not_helpful"
elif answer == "c":
comment = input(" Your comment: ").strip()
feedback_data["feedback"] = "comment"
feedback_data["comment"] = comment
else:
return # skip, no feedback to log

# Log to data/search-feedback.jsonl
log_dir = Path("data")
log_dir.mkdir(exist_ok=True)
log_file = log_dir / "search-feedback.jsonl"
with open(log_file, "a", encoding="utf-8") as f:
f.write(json.dumps(feedback_data) + "\n")
print(f" ✅ Feedback saved to {log_file}")
print()
except (EOFError, KeyboardInterrupt):
print()
pass # Non-interactive mode, skip feedback


def main():
_ensure_utf8_stdout()
args = sys.argv[1:]
Expand Down Expand Up @@ -515,6 +550,7 @@ def main():
explain = False
verbose = False
agent_mode = False
feedback = False
strict = False
env_filter: Optional[str] = None
lang: Optional[str] = None
Expand Down Expand Up @@ -568,6 +604,8 @@ def main():
explain = True
elif arg == "--agent":
agent_mode = True
elif arg == "--feedback":
feedback = True
elif arg == "--strict":
strict = True
elif arg.startswith("--env="):
Expand Down Expand Up @@ -751,6 +789,8 @@ def main():
print(f" 💡 View full content: cat lessons/<filename>.md")
print(f" 💡 Contribute new knowledge: python3 scripts/queue_lesson.py -t 'title' -d domain 'content...'")
print()
if feedback:
_prompt_feedback(query, found_any)


def _harvest_from_file(filepath: str):
Expand Down
Loading