Overview
Finance Agent is built on a modern stack optimized for AI-powered retrieval-augmented generation (RAG) and real-time streaming responses.Backend Stack
Web Framework
FastAPI - Modern, high-performance Python web framework- Automatic OpenAPI/Swagger documentation
- Built-in request validation with Pydantic
- Native async/await support for streaming responses
- Type hints for IDE support and runtime validation
- High-performance async server
- WebSocket support for streaming
- Production-ready with standard configuration
- Lightweight and fast
- WebSocket and streaming support
Database & Storage
PostgreSQL 12+ - Primary relational database- Stores transcript chunks, 10-K chunks, and metadata
- JSONB support for flexible metadata storage
- Robust ACID guarantees for data consistency
- Efficient storage of 384-dimensional embeddings
- Native PostgreSQL vector operations
- Hybrid search combining vector similarity with traditional SQL
- Used for financial data analysis and screening
- Fast aggregations over company fundamentals
- Full transcript text and SEC filing documents
- Cost-effective storage for large documents
- Separation of embeddings (PostgreSQL) from full text (S3)
- Session caching and rate limiting
- Optional dependency for production deployments
AI/ML Stack
Language Models:- Cerebras (primary) - Qwen-3-235B-A22B-Instruct-2507
- Fast inference for question analysis, response generation, evaluation
- Configured via
CEREBRAS_API_KEY
- OpenAI (fallback) - GPT-5-nano-2025-08-07
- Backup LLM provider
- Configured via
OPENAI_API_KEY
- Provider Selection - Configurable via
llm_providerinrag/config.py(“cerebras” | “openai” | “auto”)
- sentence-transformers -
all-MiniLM-L6-v2model- 384-dimensional dense vectors
- Optimized for semantic similarity search
- Lightweight and fast inference
- LangChain - Orchestration and utilities
- Text splitters for chunking transcripts
- Community integrations for data sources
- Core abstractions for LLM interactions
Search & Retrieval
Hybrid Search Strategy:- Vector Search (70% weight) - Semantic similarity via pgvector
- Keyword Search (30% weight) - TF-IDF for exact term matching
- Cross-encoder Reranking - Re-scores results for relevance (SEC agent)
- Earnings Transcripts - Hybrid vector + keyword search (
search_engine.py) - SEC 10-K Filings - Specialized retrieval agent with section routing (
sec_filings_service_smart_parallel.py) - Real-Time News - Tavily API integration (
tavily_service.py)
Authentication & Security
Clerk - User authentication (production)- JWKS-based JWT verification (RS256)
- Secure token validation
- Configured via
CLERK_SECRET_KEYandCLERK_PUBLISHABLE_KEY
- RS256 signature verification
- Required for Clerk integration
python-jose,passlib,Authlib, Google OAuth libraries- Retained for backward compatibility
Python Dependencies
Key libraries fromrequirements.txt:
Frontend Stack
Core Framework
React 19.2 - UI library- Latest version with improved hooks and concurrent features
- Component-based architecture
- Virtual DOM for performance
- Compile-time type checking
- Enhanced IDE support
- Reduced runtime errors
- Fast hot module replacement (HMR)
- Optimized production builds
- Native ES modules support
UI & Styling
Tailwind CSS 4.1 - Utility-first CSS framework- Rapid UI development
- Consistent design system
- Minimal bundle size with tree-shaking
- Prose styles for markdown content
- Responsive text scaling
- Smooth transitions and animations
- Gesture support
- Layout animations
- Modern, consistent icon set
- Tree-shakeable for small bundle size
Routing & Markdown
React Router DOM 7.13 - Client-side routing- Nested routes and layouts
- Programmatic navigation
- URL parameter handling
- GitHub-flavored markdown support
- Code syntax highlighting
- Custom component rendering
- Tables, task lists, strikethrough
- Auto-linking
- Allows custom HTML elements in markdown
Authentication & Analytics
Clerk React - Authentication UI- Pre-built sign-in/sign-up components
- User management
- Session handling
- User behavior tracking
- Feature flags
- Session replay
Frontend Dependencies
Key libraries fromfrontend/package.json:
External Services
Required APIs
| Service | Purpose | Environment Variable |
|---|---|---|
| Cerebras | Primary LLM (Qwen-3-235B) | CEREBRAS_API_KEY |
| OpenAI | Fallback LLM (GPT-5-nano) | OPENAI_API_KEY |
| API Ninjas | Company metadata | API_NINJAS_KEY |
| Clerk | Authentication (production) | CLERK_SECRET_KEY, CLERK_PUBLISHABLE_KEY |
Optional APIs
| Service | Purpose | Environment Variable |
|---|---|---|
| Tavily | Real-time news search | TAVILY_API_KEY |
| Logfire | Observability and monitoring | LOGFIRE_TOKEN |
| Redis | Caching and session storage | REDIS_URL |
Development Tools
Backend:- Tenacity - Retry logic with exponential backoff
- Logfire - Observability for FastAPI and asyncpg
- Pydantic Settings - Environment variable management
- ESLint - Code linting
- TypeScript ESLint - TypeScript-specific linting rules
- Vite - Development server with HMR
Performance Optimizations
- Async/Await - Non-blocking I/O throughout backend
- Streaming Responses - Real-time answer generation and progress updates
- Parallel Execution - Multi-ticker queries run concurrently
- Connection Pooling - Efficient database connection management (asyncpg)
- Vector Indexing - Fast similarity search with pgvector IVFFlat indexes
- Hybrid Search - Combines semantic and keyword search for better recall
- Cross-encoder Reranking - Improves precision for SEC filings
- Redis Caching - Reduces redundant database queries (optional)
Next Steps
Project Structure
Understand the codebase organization
Database Schema
Explore the data models and tables