A financial assistant powered by Large Language Models (LLMs) with Retrieval-Augmented Generation (RAG) capabilities for analyzing company risks. This project demonstrates advanced AI techniques including tool calling, semantic search, and cloud-based LLM support with planned local provider support.
- Cloud-Based LLM Support: Powered by AWS Bedrock (cloud) provider
- Future Implementation: Ollama (local) provider support planned
- Tool Calling: Integrated financial tools for stock prices, calculations, and risk analysis
- RAG Implementation: Semantic search capabilities using PostgreSQL with pgvector for contextual risk analysis
- Structured Output: Enforces consistent JSON responses through schema validation
- Interactive Chat Interface: Conversational interface for querying financial risks
- Database Integration: PostgreSQL backend with sample risk data for major tech companies
This financial assistant specializes in risk analysis for publicly traded companies. Users can ask questions about company risks, and the assistant will:
- Search for relevant risks using semantic similarity
- Retrieve detailed risk information when needed
- Provide structured, contextual responses with confidence ratings
app/agent.py: Main finance assistant with tool calling orchestrationapp/llm.py: Abstraction layer supporting AWS Bedrock provider (Ollama support planned)app/rag.py: RAG implementation with PostgreSQL/pgvector for semantic searchdatabase/: Database schema and sample risk data for major tech companiestests/: Comprehensive test suite covering functionality and schema validation
- Python 3.8+
- Docker (for database)
- AWS account with Bedrock access and quota for desired models
- (Ollama support planned for local LLM usage)
git clone https://github.com/yourusername/fintech-risk-assistant.git
cd fintech-risk-assistantpython -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txt# Build the database container
cd database
docker build -t fintech-db .
cd ..
# Run the database container
docker run --rm -d -p 5432:5432 \
-e POSTGRES_DB=fintech \
-e POSTGRES_USER=myuser \
-e POSTGRES_PASSWORD=mypassword \
--name fintech-database fintech-dbAfter starting the database, you need to update the risk embeddings for the RAG functionality to work properly:
# Run the embedding update script
python app/rag.pyWith AWS Bedrock (default):
python app/agent.pyWith specific Bedrock models:
BEDROCK_MODEL_ID=amazon.nova-lite-v1:0 python app/agent.py
BEDROCK_MODEL_ID=openai.gpt-oss-20b-1:0 python app/agent.py
BEDROCK_MODEL_ID=deepseek.v3.2 python agent.pyNote: Requires AWS account with Bedrock access and quota for the specified models.
(Ollama support planned for local LLM usage)
Example questions to ask:
- "Which companies face cybersecurity risks?"
- "Are there any supply chain issues in the database?"
- "What regulatory challenges is Google facing?"
- Tools are defined as simple Python functions with typed arguments
- Each tool has a corresponding Pydantic model for validation
- Tools are registered in centralized collections (
TOOLS,REGISTRY,ARG_MODELS) - Tool specifications are built dynamically and passed to LLM providers
- Structured responses are enforced using JSON schema validation
- Unified
llm.chat()for regular conversations with tool calling - Unified
llm.chat_structured()for schema-enforced responses - Provider differences abstracted behind common interfaces
- Automatic conversion between provider-specific formats
- Currently supports AWS Bedrock with planned Ollama support
Note: Embeddings for RAG are generated using the Amazon Bedrock Titan model.
- Uses PostgreSQL with pgvector extension for semantic search
- Connects to local database via Docker container
- Embeddings generated using Amazon Bedrock Titan model
- Semantic similarity search with relevance scoring
- Requires manual update of risk embeddings after database initialization
The database includes sample risk data for major tech companies:
| Company | Ticker | Risk Categories |
|---|---|---|
| Microsoft | MSFT | Cybersecurity |
| GOOGL | Regulatory | |
| Apple | AAPL | Supply Chain |
| Amazon | AMZN | Regulatory |
Configure the LLM provider using environment variables:
# AWS Bedrock (default)
export LLM_PROVIDER=bedrock
export BEDROCK_REGION=us-east-1
export BEDROCK_MODEL_ID=amazon.nova-lite-v1:0
# Ollama support (planned for future implementation)
# export LLM_PROVIDER=ollama
# export OLLAMA_MODEL=qwen2.5:7bThe RAG component connects to PostgreSQL using:
postgresql://myuser:mypassword@localhost:5432/fintech
# Ensure database is running first
python -m pytest tests/├── app/
│ ├── agent.py # Main assistant logic
│ ├── llm.py # LLM abstraction layer
│ ├── rag.py # RAG implementation
│ ├── helloBedrock.py # Bedrock example
│ ├── helloOllama.py # Ollama example (disabled)
│ └── utils.py # Utility functions
├── database/
│ ├── Dockerfile # Database container definition
│ ├── schema.sql # Database schema
│ └── seed_data.py # Sample data generator
├── tests/
│ ├── test_agent.py # Agent functionality tests
│ └── test_schema.py # Database schema tests
└── requirements.txt # Python dependencies
flowchart LR
U(["User CLI"]) -->|Question| A["Agent Loop<br/>agent.py"]
A <-->|Tool Calls| B["AWS Bedrock<br/>Nova Lite"]
A <-->|Vector Search| DB[("PostgreSQL<br/>pgvector")]
A -->|Validate| P["Pydantic<br/>FinalAnswer JSON"]