Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
AI Enrichment Scripts
Scripts for AI-powered legislative analysis using Intel Arc Graphics optimization.
π― What's Here
- intel_llm_setup.sh - One-command setup for Intel Arc GPU + NPU optimization
- legislative_analysis_intel.py - DuckDB + Llama for bill & testimony analysis
- batch_analyze_bills.py - Batch process bills with incremental support β
- query_analysis_results.py - Query and export analysis results from Parquet β
- duckdb_vss_demo.py - Vector similarity search benchmarking
π Data Pipeline Architecture
Why Parquet + DuckDB?
Source Data (Parquet)
β
DuckDB Query Engine (10-100x faster than Postgres!)
β
AI Analysis (Llama 3.2/3.3)
β
Results (Parquet) β Incremental appends, portable, version-controlled
Benefits:
- β Parquet storage - portable, fast, works with Pandas/Spark/DuckDB
- β DuckDB queries - no database server, 10-100x faster than Postgres
- β Incremental processing - skip already-analyzed bills, resume after failures
- β Version control - track analysis results in git (if small) or DVC
β‘ Your Hardware
You have: Intel Core Ultra 7 165H
- β Arc Graphics (integrated GPU)
- β NPU (Neural Processing Unit)
- β Perfect for running Llama models locally
π Quick Start
1. Run the Setup Script
cd /home/developer/projects/open-navigator
./scripts/enrichment_ai/intel_llm_setup.sh
This will:
- Create
.venv-intelvirtual environment - Install Intel Extension for PyTorch (IPEX)
- Install OpenVINO for Arc GPU acceleration
- Install DuckDB with VSS (Vector Similarity Search)
- Install Llama model libraries
2. Activate the Environment
source .venv-intel/bin/activate
3. Run Demo (Shows Incremental Processing)
# See architecture and check for existing analysis
python scripts/enrichment_ai/legislative_analysis_intel.py
4. Batch Analyze Bills (Saves to Parquet!)
# Analyze 10 Georgia fluoride bills (incremental - skips already-analyzed)
python scripts/enrichment_ai/batch_analyze_bills.py --state GA --topic fluorid --limit 10
# Analyze 50 Alabama bills
python scripts/enrichment_ai/batch_analyze_bills.py --state AL --limit 50
# Re-analyze everything (disable incremental)
python scripts/enrichment_ai/batch_analyze_bills.py --state GA --no-incremental
5. Query Results
# View analysis summary and recent results
python scripts/enrichment_ai/query_analysis_results.py
# Filter by state
python scripts/enrichment_ai/query_analysis_results.py --state GA
# Find specific organizations
python scripts/enrichment_ai/query_analysis_results.py --group "Dental Association"
Using DuckDB CLI:
# Show all results
duckdb -c "SELECT * FROM read_parquet('data/gold/analysis/interest_groups_analysis.parquet') LIMIT 5"
# Find opposing groups
duckdb -c "SELECT group_name, bill_id, stance_score FROM read_parquet('data/gold/analysis/*.parquet') WHERE stance='oppose' ORDER BY stance_score LIMIT 10"
# Export to CSV
duckdb -c "COPY (SELECT * FROM read_parquet('data/gold/analysis/*.parquet')) TO 'results.csv' (HEADER, DELIMITER ',')"
Using Python/Pandas:
import pandas as pd
# Read Parquet directly
df = pd.read_parquet('data/gold/analysis/interest_groups_analysis.parquet')
# Filter and analyze
support = df[df['stance'] == 'support']
oppose = df[df['stance'] == 'oppose']
print(f"Supporting: {len(support)}, Opposing: {len(oppose)}")
# Export
df.to_csv('analysis_results.csv', index=False)
df.to_json('analysis_results.json', orient='records')
π¦ What Gets Installed
The setup script installs from requirements-intel.txt:
Core AI Libraries:
intel-extension-for-pytorch- GPU acceleration for Arc Graphicsoptimum[openvino]- Intel's optimized inference enginetransformers- Hugging Face model librarysentence-transformers- Embedding generation
Database:
duckdb- Fast analytical queries (10-100x faster than Postgres)- VSS extension - Vector similarity search with HNSW index
Models Supported:
- Llama 3.2 (3B, 8B models)
- Llama 3.3 (via Ollama)
- Any Hugging Face model
π― Performance Expectations
On your Intel Core Ultra 7 165H:
| Task | Speed |
|---|---|
| LLM inference | 350-1,200 tokens/sec |
| Vector search (10K records) | ~18ms |
| Context injection (100 bills) | ~20ms |
| Full testimony analysis | ~80ms |
β‘ Current LLM Performance Status
Two Options Available:
| Method | Status | Performance | Notes |
|---|---|---|---|
| Ollama llama3.2 | β Working | ~2 min/bill | Subprocess call, slower but reliable |
| HuggingFace Transformers | β³ Pending Access | ~30 sec/bill | Intel GPU optimized, 4x faster |
Why the difference?
- Ollama: Runs as separate process, requires subprocess communication overhead
- HuggingFace: Direct library calls, optimized with Intel IPEX + OpenVINO
Current Recommendation:
- Use Ollama for testing and prototyping (working now)
- HuggingFace access pending - will be significantly faster for batch processing
- Both use the same
batch_analyze_bills.pyscript
β οΈ Important Notes
Did You Download the Right Bundle?
β YES if you have:
- Intel Core Ultra 7 165H (you do!)
- Requirements file:
requirements-intel.txt(you do!) - Setup script:
intel_llm_setup.sh(you do!)
β NO if you're using:
requirements.txt(generic, no Intel optimization)requirements-cpu.txt(CPU-only, slower)
Next Steps:
- Run
./scripts/enrichment_ai/intel_llm_setup.sh - Activate with
source .venv-intel/bin/activate - Test with vector search demo
- Run legislative analysis
π§ Environment Variables (Optional)
For maximum performance, set these before running:
export ZES_ENABLE_SYSMAN=1 # Enable GPU monitoring
export IPEX_LLM_NUM_GPU=1 # Use Arc Graphics
export OLLAMA_NUM_GPU=999 # If using Ollama
π Usage Examples
See the Python files for detailed examples:
- Vector search patterns
- LLM prompt engineering
- Structured data extraction
- Bill & testimony analysis