-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhaystack_interactive_demo.py
More file actions
62 lines (49 loc) Β· 1.93 KB
/
haystack_interactive_demo.py
File metadata and controls
62 lines (49 loc) Β· 1.93 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
"""
Interactive Haystack RAG Demo
Run this to interact with the Haystack-style RAG system.
"""
from haystack_demo import HaystackStyleRAG
import os
def main():
"""Interactive Haystack RAG demo."""
print("π€ Interactive Haystack RAG Demo")
print("=" * 50)
# Initialize RAG system
rag = HaystackStyleRAG(document_dir="documents")
# Load documents
rag.load_documents()
if not rag.document_store:
print("β No documents loaded. Please check your documents directory.")
return
print(f"β
System ready! {len(rag.document_store)} documents in document store.")
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
# Run the Haystack-style pipeline
results = rag.run_pipeline(question, top_k=3)
if results['documents']:
print(f"π€ Answer: {results['answer']}")
print(f"π Sources: {', '.join(results['sources'])}")
print(f"π Retrieved {len(results['documents'])} relevant documents")
else:
print("β No relevant documents 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()