Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ AI-Powered Financial Analysis System

Complete RAG-enhanced autonomous financial analysis with integrated validation quality gates and vector database acceleration.


πŸ“‹ System Overview

A production-ready AI financial analysis system featuring:

  • πŸ€– Autonomous Agent: Self-directed financial analysis with multi-step reasoning
  • ⚑ RAG Enhancement: Vector database-powered context augmentation using Qdrant
  • 🎯 Prompt Engine: Intelligent prompt generation with template management
  • πŸ”’ Validation System: Automated quality assessment with blocking quality gates
  • 🧠 LLM Integration: Real-time Ollama integration for analysis generation
  • πŸ’Ύ Vector Learning: Continuous improvement through interaction patterns
  • 🎨 Modern UI: Beautiful responsive interfaces with real-time feedback

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     USER INTERFACE                          β”‚
β”‚         (Port 5001: Main & Simple Interface)                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
                            β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  AUTONOMOUS AGENT (Port 5001)               β”‚
β”‚  β€’ Financial Analysis    β€’ RAG Enhancement                  β”‚
β”‚  β€’ Multi-step Reasoning  β€’ Pattern Recognition              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                  β”‚                  β”‚
         β–Ό                  β–Ό                  β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ PROMPT ENGINEβ”‚  β”‚   QDRANT     β”‚  β”‚ VALIDATION SYSTEM    β”‚
β”‚  (Port 5000) β”‚  β”‚ (Port 6333)  β”‚  β”‚    (Port 5002)       β”‚
β”‚              β”‚  β”‚              β”‚  β”‚                      β”‚
β”‚ β€’ Templates  β”‚  β”‚ β€’ Vectors    β”‚  β”‚ β€’ Quality Check      β”‚
β”‚ β€’ Generation β”‚  β”‚ β€’ Similarity β”‚  β”‚ β€’ Score Assessment   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                                      β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    OLLAMA    β”‚
                    β”‚ (Port 11434) β”‚
                    β”‚              β”‚
                    β”‚ β€’ LLM Models β”‚
                    β”‚ β€’ Text Gen   β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🌟 Key Features

Complete Analysis Pipeline

  1. Financial data β†’ Prompt Engine
  2. Prompt generation β†’ Autonomous Agent
  3. RAG enhancement β†’ Vector search (Qdrant)
  4. Analysis generation β†’ LLM (Ollama)
  5. Validation β†’ Quality assessment
  6. Validated response β†’ User interface

Integrated Validation System

  • Automated quality gates with configurable thresholds
  • Multi-criteria assessment: Accuracy, Completeness, Clarity, Relevance
  • Real-time scoring: Instant quality metrics (0-100%)
  • Quality levels: Exemplary (β‰₯95%), High Quality (β‰₯80%), Acceptable (β‰₯65%)
  • Fast validation: Optimized for <20 second response times

RAG-Enhanced Intelligence

  • Vector database acceleration: Lightning-fast context retrieval
  • Similarity search: Finds relevant historical patterns
  • Context augmentation: Enriches analysis with domain knowledge
  • Continuous learning: Improves with each interaction

Autonomous Capabilities

  • Self-directed analysis: No manual intervention needed
  • Multi-step reasoning: Structured analytical frameworks
  • Context inference: Automatically detects data types and scenarios
  • Confidence scoring: Transparency in analysis quality

πŸš€ Quick Start

Prerequisites

  • Python 3.12 or 3.13
  • Docker (for Ollama and Qdrant)
  • 8GB+ RAM recommended
  • 10GB+ disk space for LLM models

1. Clone the Repository

git clone <repository-url>
cd prompt-engine

2. Set Up Virtual Environment

python -m venv prompt
source prompt/bin/activate  # On Windows: prompt\Scripts\activate
pip install -r requirements.txt

3. Start Docker Services

# Start Ollama and Qdrant
docker-compose up -d

4. Pull LLM Models

# Pull required models
ollama pull mistral:latest
ollama pull llama3.1:8b
ollama pull phi3:3.8b

# Verify models
ollama list

5. Start All Services

Terminal 1 - Prompt Engine:

python server.py

Terminal 2 - Autonomous Agent:

cd autonomous-agent
source agent/bin/activate
python server_final.py

Terminal 3 - Validation System:

cd validation-llm
source ../prompt/bin/activate
python simple_server.py

6. Access the System


🎯 System Components

1. Prompt Engine (Port 5000)

Intelligent prompt generation with template management.

Key Endpoints:

  • GET /health - System health check
  • GET /system/status - Comprehensive status
  • POST /generate - Generate prompts
  • GET /ollama/models - List available LLM models

Features:

  • Template-based prompt generation
  • Dynamic context inference
  • Multi-type generation (standard, reasoning, autonomous)
  • Vector database integration

2. Autonomous Agent (Port 5001)

Self-directed financial analysis with RAG enhancement.

Key Endpoints:

  • GET /agent/status - Agent health and capabilities
  • POST /analyze - Complete analysis with validation
  • POST /pipeline/full - Full RAG pipeline
  • POST /pipeline/agentic - Agentic pipeline
  • POST /feedback/validation - Receive validation feedback

Features:

  • RAG-enhanced analysis
  • Multi-step reasoning frameworks
  • Automated validation integration
  • Confidence scoring
  • Pattern learning

3. Validation System (Port 5002)

Automated quality assessment with blocking quality gates.

Key Endpoints:

  • GET /health - Service health check
  • POST /validate/response - Validate analysis quality
  • GET /validation/status - Validation service status

Features:

  • Multi-criteria quality assessment
  • Configurable quality gates
  • Fast validation (<20 seconds)
  • Detailed scoring breakdowns
  • Quality level classification

4. Vector Database (Qdrant - Port 6333)

High-performance vector storage and similarity search.

Collections:

  • financial_knowledge_base - Domain knowledge
  • data_insights - Analysis patterns
  • interaction_patterns - User interaction history
  • agentic_prompts - Successful prompts
  • successful_patterns - High-quality patterns

5. LLM Service (Ollama - Port 11434)

Local LLM inference for text generation.

Recommended Models:

  • mistral:latest - Validation (fast, accurate)
  • llama3.1:8b - Analysis (comprehensive)
  • phi3:3.8b - Prompt generation (efficient)

πŸ“Š API Usage Examples

Complete Analysis (Autonomous Agent)

curl -X POST http://localhost:5001/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "input_data": {
      "transactions": [
        {
          "date": "2024-01-15",
          "amount": 1500.00,
          "type": "credit",
          "description": "Salary"
        },
        {
          "date": "2024-01-16",
          "amount": -50.00,
          "type": "debit",
          "description": "Grocery"
        }
      ],
      "account_balance": 2250.00,
      "customer_id": "CUST_001"
    },
    "request_config": {
      "generation_type": "autonomous",
      "include_validation": true
    }
  }'

Response:

{
  "analysis": "=== SECTION 1: INSIGHTS ===\nComprehensive financial analysis...\n=== SECTION 2: RECOMMENDATIONS ===\nActionable recommendations...",
  "metadata": {
    "processing_time": 16.2,
    "rag_items_found": 3,
    "confidence_score": 0.85
  },
  "validation": {
    "quality_level": "high_quality",
    "overall_score": 0.805,
    "quality_approved": true,
    "validation_status": "approved",
    "criteria_scores": {
      "accuracy": 0.85,
      "completeness": 0.80,
      "clarity": 0.88,
      "relevance": 0.75
    },
    "validation_time": 3.2
  },
  "timestamp": "2025-01-15T10:30:00Z"
}

Direct Validation

curl -X POST http://localhost:5002/validate/response \
  -H "Content-Type: application/json" \
  -d '{
    "response_data": {
      "analysis": "=== SECTION 1: INSIGHTS ===\nGood analysis.\n=== SECTION 2: RECOMMENDATIONS ===\nClear recommendations."
    },
    "input_data": {
      "transactions": [
        {"date": "2024-01-15", "amount": 1500.00, "type": "credit"}
      ]
    }
  }'

System Status Check

# Check all services
curl http://localhost:5000/health      # Prompt Engine
curl http://localhost:5001/agent/status # Autonomous Agent
curl http://localhost:5002/health      # Validation System
curl http://localhost:11434/api/tags   # Ollama
curl http://localhost:6333/collections # Qdrant

πŸ§ͺ Testing

Comprehensive System Test

python test_system_comprehensive.py

This test verifies:

  • βœ… All service connectivity
  • βœ… Ollama model availability
  • βœ… Prompt generation functionality
  • βœ… Autonomous agent analysis
  • βœ… Validation system integration
  • βœ… Qdrant vector database
  • βœ… End-to-end workflow

Expected Results:

  • All services operational
  • Validation scores > 65%
  • Processing times < 30 seconds
  • No connection errors

Test Files

  • test_system_comprehensive.py - Complete system test
  • test_validation_ui_fix.py - Validation UI testing
  • test_fixes.py - Quick fixes verification

πŸ“ˆ Performance Metrics

Expected Processing Times

Component Time Notes
Prompt Generation 0.1-1s Very fast
RAG Enhancement 1-2s Vector search
Analysis Generation 8-12s LLM processing
Validation 5-10s Quality assessment
Total End-to-End 15-25s Complete pipeline

Validation Quality Levels

Level Score Status
Exemplary β‰₯ 95% πŸ† Outstanding
High Quality β‰₯ 80% βœ… Approved
Acceptable β‰₯ 65% πŸ‘ Acceptable
Poor < 65% ⚠️ Needs improvement

System Capacity

  • Concurrent Requests: 10-20 simultaneous analyses
  • Vector Database: Millions of embeddings
  • Pattern Storage: Unlimited with Qdrant
  • Learning Rate: Continuous improvement

πŸ”§ Configuration

Service Ports

Service Port Configurable In
Prompt Engine 5000 config.py
Autonomous Agent 5001 autonomous-agent/config.py
Validation System 5002 validation-llm/config.py
Ollama 11434 Docker Compose
Qdrant 6333 Docker Compose

Model Configuration

Edit validation-llm/config.py:

VALIDATION_LLM_CONFIG = {
    "primary_validator": {
        "model_name": "mistral:latest",
        "timeout": 15,
        "max_tokens": 100
    },
    "speed_validator": {
        "model_name": "mistral:latest",
        "timeout": 10,
        "max_tokens": 50
    }
}

Quality Gate Thresholds

Edit autonomous-agent/core/validation_integration.py:

self.quality_gates = {
    "exemplary": 0.95,
    "high_quality": 0.80,
    "acceptable": 0.65,
    "poor": 0.0
}

πŸ› οΈ Troubleshooting

Common Issues

1. Service Not Starting

# Check port availability
lsof -i :5000
lsof -i :5001
lsof -i :5002

# Kill processes if needed
kill -9 <PID>

2. Ollama Connection Failed

# Check Ollama is running
docker ps | grep ollama

# Test connection
curl http://localhost:11434/api/tags

# Restart if needed
docker restart ollama

3. Validation Timeout

  • Check Ollama models are pulled: ollama list
  • Verify validation config timeout settings
  • Ensure system has enough RAM (8GB+)
  • Check system resources: top or htop

4. Vector Database Issues

# Check Qdrant is running
curl http://localhost:6333/collections

# Restart Qdrant
docker restart qdrant

# Check logs
docker logs qdrant

5. Python Version Issues

# System uses Python 3.12
python --version

# Create fresh venv
python3.12 -m venv prompt
source prompt/bin/activate
pip install -r requirements.txt

Debug Mode

# Enable debug logging in each service
export FLASK_DEBUG=1

# Run with verbose output
python server.py --verbose

πŸ“š Documentation

Main Documentation

  • README.md - This file (system overview)
  • SYSTEM_API_DOCUMENTATION.md - Complete API reference
  • TEST_RESULTS_EXPLAINED.md - Understanding test results
  • TESTING_GUIDE.md - Testing procedures

Component Documentation

  • VALIDATION_UI_INTEGRATION.md - Validation UI details
  • VALIDATION_STATUS_FEATURES.md - Validation features
  • BLOCKING_VALIDATION_INTEGRATION.md - Quality gates

Setup Documentation

  • docker-setup.sh - Docker setup script
  • setup_qdrant.sh - Qdrant setup
  • requirements.txt - Python dependencies

🎨 User Interfaces

Main Interface (http://localhost:5001)

  • Complete analysis UI with all features
  • RAG metadata display showing context items
  • Validation results with quality scores
  • Real-time status updates
  • Interactive controls

Simple Interface (http://localhost:5001/simple)

  • Streamlined UI for quick analysis
  • Pipeline flow visualization
  • Debug mode for development
  • Compact validation display
  • Performance metrics

Pipeline Flow Display:

Step 1: Financial data β†’ 
Step 2: Prompt Engine β†’ 
Step 3: RAG Enhancement β†’ 
Step 4: Analysis Generation β†’ 
Step 5: Validation β†’ 
Step 6: Validated Response

πŸ”„ Data Flow

Complete Analysis Flow

  1. User submits financial data via UI
  2. Autonomous agent receives request
  3. Prompt engine generates structured prompt
  4. RAG service enhances with vector context
  5. LLM (Ollama) generates analysis
  6. Validation system assesses quality
  7. Quality gates approve or flag issues
  8. Validated response returned to user
  9. Pattern stored in vector database for learning

Validation Process

  1. Response received from analysis
  2. Multi-criteria assessment:
    • Accuracy validation
    • Completeness check
    • Clarity evaluation
    • Relevance scoring
  3. Score calculation (0-100%)
  4. Quality level assignment
  5. Approval decision based on gates
  6. Feedback sent to autonomous agent

πŸ“Š Monitoring

Health Checks

# Quick health check all services
curl http://localhost:5000/health && echo "βœ… Prompt Engine"
curl http://localhost:5001/agent/status && echo "βœ… Autonomous Agent"
curl http://localhost:5002/health && echo "βœ… Validation System"
curl http://localhost:11434/api/tags && echo "βœ… Ollama"
curl http://localhost:6333/collections && echo "βœ… Qdrant"

Performance Monitoring

  • Monitor processing times in UI
  • Check validation scores for quality trends
  • Review RAG context usage
  • Track pattern learning in Qdrant
  • Analyze system resource usage

Logs

# Service logs
tail -f prompt_engine.log
tail -f autonomous_agent.log
tail -f validation_system.log

# Docker logs
docker logs ollama
docker logs qdrant

πŸš€ Production Deployment

System Requirements

  • CPU: 4+ cores (8+ recommended)
  • RAM: 16GB minimum (32GB recommended)
  • Storage: 50GB+ (for models and vector database)
  • Network: Stable connection for model downloads

Security Considerations

  • Use environment variables for sensitive config
  • Enable authentication on Qdrant
  • Implement rate limiting
  • Use HTTPS in production
  • Regular security updates

Scaling

  • Deploy services on separate machines
  • Use load balancer for autonomous agent
  • Scale Qdrant cluster for high throughput
  • Cache frequently used patterns
  • Monitor and optimize bottlenecks

🀝 Contributing

Development Setup

  1. Fork the repository
  2. Create feature branch
  3. Make changes with tests
  4. Run comprehensive tests
  5. Submit pull request

Code Style

  • Follow PEP 8 for Python code
  • Use type hints where applicable
  • Add docstrings to functions
  • Comment complex logic
  • Write meaningful commit messages

πŸ“ License

This project is proprietary software. All rights reserved.


🎯 Roadmap

Current Version: 2.0

  • βœ… Complete RAG pipeline
  • βœ… Integrated validation system
  • βœ… Vector database learning
  • βœ… Modern responsive UI
  • βœ… Comprehensive testing

Future Enhancements

  • πŸ”„ Multi-language support
  • πŸ”„ Advanced analytics dashboard
  • πŸ”„ Real-time streaming responses
  • πŸ”„ Custom model fine-tuning
  • πŸ”„ API authentication
  • πŸ”„ Batch processing
  • πŸ”„ Export capabilities

πŸ“ž Support

For issues, questions, or contributions:

  1. Check documentation in /docs
  2. Review troubleshooting section
  3. Run comprehensive tests
  4. Check GitHub issues
  5. Contact development team

πŸŽ‰ The system is production-ready and fully operational!

Powered by advanced AI with RAG enhancement and automated quality validation.


Last Updated: January 2025
Version: 2.0.0
Status: βœ… Production Ready

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages