-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaystack_interactive.py
More file actions
64 lines (50 loc) · 1.9 KB
/
haystack_interactive.py
File metadata and controls
64 lines (50 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Interactive Haystack RAG Demo
Run this to interact with the Haystack RAG system.
"""
from haystack_rag import HaystackRAG
import os
def main():
"""Interactive Haystack RAG demo."""
print("🤖 Interactive Haystack RAG Demo")
print("=" * 50)
# Initialize RAG system
rag = HaystackRAG(document_dir="documents")
if not rag.pipeline:
print("❌ Pipeline setup failed. Please check your Haystack installation.")
return
# Load documents
rag.load_documents()
if not rag.document_store.get_document_count():
print("❌ No documents loaded. Please check your documents directory.")
return
print(f"✅ System ready! {rag.document_store.get_document_count()} documents loaded.")
print("\n💡 Try these sample questions:")
print(" - 'What is artificial intelligence?'")
print(" - 'What are neural networks?'")
print(" - 'What is machine learning?'")
print(" - 'How does deep learning work?'")
print("\nType 'quit' to exit")
print("-" * 50)
while True:
try:
question = input("\n❓ Your question: ").strip()
if question.lower() in ['quit', 'exit', 'q']:
print("👋 Goodbye!")
break
if not question:
continue
# Ask the question
result = rag.ask_question(question)
if result['sources']:
print(f"✅ Found {len(result['sources'])} relevant sources")
else:
print("❌ No relevant sources found")
print("💡 Try different keywords or simpler terms")
except KeyboardInterrupt:
print("\n👋 Goodbye!")
break
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
main()