| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| from src.config import create_required_folders, load_config, validate_config |
| from src.rag_pipeline import RAGPipeline |
|
|
|
|
| def print_retrieved_sources(result: dict) -> None: |
| """ |
| Print retrieved source chunks clearly. |
| """ |
|
|
| print("\nRetrieved sources:") |
|
|
| for item in result["retrieved_chunks"]: |
| print( |
| f"- Rank {item['rank']} | " |
| f"Source: {item['source']} | " |
| f"Chunk: {item['chunk_index']} | " |
| f"Distance: {item['distance']}" |
| ) |
|
|
|
|
| def main() -> None: |
| """ |
| Main demo runner. |
| """ |
|
|
| print("=" * 80) |
| print("KnowFlow AI - Phase 2 Modular RAG Pipeline Demo") |
| print("=" * 80) |
|
|
| config = load_config() |
| validate_config(config) |
| create_required_folders(config) |
|
|
| print("\nConfiguration loaded:") |
| print("Project root:", config.project_root) |
| print("Data folder:", config.data_folder) |
| print("Vector DB folder:", config.vector_db_folder) |
| print("Provider:", config.cloud_api_provider) |
| print("Model:", config.cloud_chat_model) |
| print("Embedding model:", config.embedding_model_name) |
|
|
| pipeline = RAGPipeline(config=config) |
|
|
| print("\nRebuilding vector database...") |
| rebuild_result = pipeline.rebuild_vector_database() |
| print(rebuild_result) |
|
|
| print("\nTesting cloud LLM connection...") |
| connection_answer = pipeline.llm_client.test_connection() |
| print("Connection test answer:", connection_answer) |
|
|
| demo_questions = [ |
| "What is the refund policy?", |
| "How long does standard shipping take?", |
| "What does the warranty cover?", |
| "Does the company sell customer data?", |
| "How many days of annual leave do employees get?", |
| "What is the company policy about quantum teleportation?", |
| ] |
|
|
| for question in demo_questions: |
| print("\n" + "=" * 80) |
| print("Question:") |
| print(question) |
|
|
| result = pipeline.ask(question) |
|
|
| print("\nAnswer:") |
| print(result["answer"]) |
|
|
| print_retrieved_sources(result) |
|
|
| output_path = pipeline.save_result(result) |
| print("\nSaved output:", output_path) |
|
|
| print("\n" + "=" * 80) |
| print("Phase 2 demo completed successfully.") |
| print("=" * 80) |
|
|
|
|
| if __name__ == "__main__": |
| main() |