How ruizguille/tech-trends-chatbot works
Main Components
• Frontend Component:
• Built with React and bundled using Vite.
• Contains UI components (e.g., Chatbot, ChatMessages, ChatInput) which interact with the backend API.
• Has utilities and hooks for handling UI behavior (like auto-scrolling and resizing).
• Backend Component:
• Built with Python using FastAPI.
• Contains several modules such as:
• API endpoints (located in app/api.py)
• Assistant logic (in assistants/assistant.py, local_assistant.py, prompts.py, tools.py).
• Utility functions (e.g., in utils/ for stream handling and text-splitting).
• Data processing and document loading (loader.py and export.py for exporting chats).
• Data Storage:
• Uses Redis Stack Server as the vector database (with RedisJSON and RediSearch) to store and search for vector embeddings of documents.
• Data Source:
• Raw source documents (PDF reports, etc.) stored under backend/data/docs, which are processed to build the knowledge base.
• External Services:
• OpenAI API, used by the backend to generate responses based on the provided prompts and context.
Relationships and Interactions
• The Backend includes:
• A request handling layer (main.py and api.py) that incoming requests pass through.
• Business logic embedded in the assistants module and associated configurations (config.py).
• The Backend connects to Redis for querying/storing vector embeddings, especially during:
• Document ingestion/processing, where the loader reads PDFs, transforms them into embeddings, and stores them.
• Real-time retrieval when the chatbot answers queries.
• The Backend makes outbound calls to the OpenAI API to generate responses using the intelligent prompt handling in the assistants modules.
• Optional local testing mode (“local” script) and export functionality showcase additional utility paths.
Architectural Patterns and Principles
• Separation of concerns is clearly visible: Frontend and Backend are isolated, with each having its own configuration and build system.
• Modular design: Backend components such as API endpoints, assistants, and utilities are decoupled, easing maintenance and extension.
• Customizable data ingestion pipeline: The loader system is designed to process and convert new documents into embeddings, enabling adaptivity for different data sources.
• Use of environment variables and configuration management (via Pydantic settings) ensures scalability and easy environment-specific adjustments.
• API-driven design for frontend-backend communication.