Skip to main content

Financial Agent

RAG-powered agent for querying SEC financial filings (10-K annual reports).

Ask questions about company finances, risks, business models, and more - with citations from official SEC documents.

Installation

pip install financial-agent

Quick Start

1. Get a Gemini API Key (free)

Get your free API key at: https://aistudio.google.com/app/apikey

2. Set Environment Variable

export GOOGLE_API_KEY=your-api-key-here

3. Download Vector Database

Download the pre-built vector database from GitHub Releases and extract it.

4. Use the Agent

from financial_agent import FinancialAgent

# Initialize with path to vector database
agent = FinancialAgent("path/to/vector_db")

# Ask a question
result = agent.query("What are Apple's main revenue sources?")

# Print the answer
print(result["answer"])

# Print citations
for citation in result["citations"]:
    print(f"[{citation['reference_number']}] {citation['user_friendly_format']}")

Features

  • Natural Language Queries: Ask questions in plain English
  • Multi-Company Support: Query data from AAPL, MSFT, GOOGL, AMZN, TSLA, META, NFLX, NVDA, WMT
  • Citations: Every answer includes references to source documents
  • Smart Retrieval: Hybrid search combining semantic similarity and keyword matching

Example Queries

# Single company questions
agent.query("What are Apple's main revenue sources?")
agent.query("What risks does Tesla face?")

# Comparison questions
agent.query("Compare Apple and Microsoft's business models")

# Specific topics
agent.query("What does Amazon say about competition?")

Response Format

result = agent.query("What are Apple's revenues?")

# result contains:
{
    "query": "What are Apple's revenues?",
    "answer": "According to Apple's 2023 annual report...",
    "citations": [...],
    "retrieved_chunks": 5,
    "model_used": "gemini-2.0-flash-exp",
    "timestamp": "2024-01-15T10:30:00"
}

Requirements

  • Python 3.9+
  • Google Gemini API key (free tier available)
  • Pre-built vector database (download from releases)

Building Your Own Vector Database (Advanced)

If you want to build your own vector database with fresh data or different companies, follow these instructions.

Pipeline Setup

git clone https://github.com/YOUR_USERNAME/financial-agent.git
cd financial-agent
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[pipeline]"

# Download spaCy model
python -m spacy download en_core_web_sm

Environment Variables

Create a .env file:

# SEC API (from sec-api.io)
SEC_API_KEY=your_sec_api_key_here
CONTACT_EMAIL=your_email@example.com

# Google Cloud / Vertex AI (for embeddings)
GCP_PROJECT_ID=your-gcp-project-id
GOOGLE_CLOUD_LOCATION=us-central1

Run the Pipeline

# 1. Download SEC filings
python scripts/01_download_filings.py

# 2. Clean filing text
python scripts/02_clean_sec_data.py

# 3. Analyze document structure
python scripts/03_analyze_documents.py

# 4. Create chunks
python scripts/04_create_chunks.py

# 5. Generate embeddings (requires GCP)
python scripts/05_create_embeddings.py

# 6. Set up vector database
python scripts/06_setup_vector_db.py

Project Structure

financial-agent/
├── src/
│   └── financial_agent/        # The pip-installable library
│       ├── __init__.py
│       ├── agent.py            # FinancialAgent class
│       ├── vector_db.py        # Vector database search
│       └── chunk_utils.py      # Text chunking utilities
├── scripts/                    # Data pipeline scripts
│   ├── 01_download_filings.py
│   ├── 02_clean_sec_data.py
│   ├── 03_analyze_documents.py
│   ├── 04_create_chunks.py
│   ├── 05_create_embeddings.py
│   └── 06_setup_vector_db.py
├── vector_db/                  # Pre-built FAISS index
├── pyproject.toml
└── README.md

License

MIT

Metadata

Release files for financial-agent 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for financial-agent 0.1.0
File Size Uploaded Provenance
financial_agent-0.1.0.tar.gz 17.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for financial-agent 0.1.0
File Interpreter ABI Platform
financial_agent-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.5 kB

Release files / financial_agent-0.1.0.tar.gz

Download URL financial_agent-0.1.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8439548b41ee6561e5c36f9b3e5467f361bcccddc237f01e61bc7b0660ad89bc
BLAKE2b-256 checksum
How to use checksums
3da9c0675d2f58474b4ad9ed3e4035f3d05fefc720d2a6ae0ead5ee1d1882be4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Release files / financial_agent-0.1.0-py3-none-any.whl

Download URL financial_agent-0.1.0-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
421cb0079edb74e5d85d4de6b76bf9cfc91f43bc6e65cbbe8cc5389ab91106e7
BLAKE2b-256 checksum
How to use checksums
e6514e180cc8ae16bfc281ab472a45a68fd3a1d04d288c8621237f4aa3eb15bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.2

Security for financial-agent 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page