Spaces:
Runtime error
Runtime error
File size: 12,504 Bytes
87c817a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | # Confluence Integration Setup Guide
This guide walks you through setting up Confluence integration for the Fraud Model Explainability Assistant.
---
## Prerequisites
- Access to a Confluence instance (Atlassian Cloud or Data Center)
- Permission to create API tokens
- Permission to read the Confluence spaces you want to search
---
## Step 1: Get Confluence API Credentials
### Option A: Atlassian Cloud (Most Common)
1. **Get your Confluence URL**:
- Go to your Confluence instance
- Copy the URL (e.g., `https://yourcompany.atlassian.net`)
2. **Create an API Token**:
- Go to https://id.atlassian.com/manage-profile/security/api-tokens
- Click **"Create API token"**
- Give it a label (e.g., "Fraud Assistant")
- Copy the token (you won't be able to see it again!)
3. **Get your email**:
- Use the email address associated with your Atlassian account
- Recommendation: Create a service account (e.g., `fraud-bot@yourcompany.com`)
### Option B: Confluence Data Center (Self-Hosted)
1. **Get your Confluence URL**:
- Your internal Confluence URL (e.g., `https://confluence.yourcompany.com`)
2. **Create a Personal Access Token**:
- Go to Confluence β Profile β Personal Access Tokens
- Click **"Create token"**
- Give it a name and select appropriate permissions
- Copy the token
3. **Authentication**:
- For Data Center, you may use username/password or PAT
- See confluence-ingestor documentation for details
---
## Step 2: Configure Environment Variables
### Create .env File
```bash
cd fraud_model_explainability_assistant
# Copy the example file
cp .env.example .env
# Edit with your credentials
nano .env # or use your preferred editor
```
### Edit .env File
```bash
# Confluence Configuration
CONFLUENCE_URL=https://yourcompany.atlassian.net # YOUR Confluence URL
CONFLUENCE_EMAIL=your.email@company.com # YOUR email
CONFLUENCE_API_TOKEN=ATATT3xFfGF0... # YOUR API token
# Embedding Provider (free, local)
EMBEDDING_PROVIDER=huggingface
# Vector Store
VECTOR_STORE_TYPE=chroma
CHROMA_PERSIST_DIRECTORY=./chroma_db
# Optional: OpenAI (if not using Bedrock)
OPENAI_API_KEY=sk-... # YOUR OpenAI key (optional)
```
**Important**: Never commit `.env` to git! It contains secrets.
---
## Step 3: Install Dependencies
```bash
# Make sure you're in the fraud assistant directory
cd fraud_model_explainability_assistant
# Install confluence-ingestor with Strands adapter
pip install confluence-ingestor[strands,huggingface,chroma]
# Verify installation
python -c "from confluence_ingestor import ConfluenceRAG; print('β
Installation successful')"
```
---
## Step 4: Identify Confluence Spaces to Ingest
### Find Your Spaces
1. Go to Confluence β Spaces β View All Spaces
2. Identify spaces with relevant documentation:
- Model governance documentation
- Compliance policies
- Fraud investigation procedures
- Training materials
- Regulatory guidelines
### Recommended Spaces for Fraud Assistant
| Space Purpose | Example Space Key | Priority |
|---------------|-------------------|----------|
| Model Governance | `fraud-model-governance` | βββββ |
| Compliance Policies | `compliance-policies` | βββββ |
| Investigation Playbooks | `fraud-investigation` | ββββ |
| Regulatory Prep | `regulatory-compliance` | ββββ |
| Team Procedures | `fraud-analytics-team` | βββ |
### Get Space Keys
1. Go to a Confluence space
2. Look at the URL: `https://yourcompany.atlassian.net/wiki/spaces/SPACEKEY/`
3. The `SPACEKEY` is what you need
---
## Step 5: Test Confluence Connection
### Quick Connection Test
```bash
cd fraud_model_explainability_assistant
# Test Confluence connection
python -c "
from confluence_ingestor import ConfluenceClient
client = ConfluenceClient.from_env()
spaces = client.list_spaces()
print('β
Connected to Confluence!')
print(f'Found {len(spaces)} spaces')
for space in spaces[:5]:
print(f' - {space.key}: {space.name}')
"
```
**Expected Output**:
```
β
Connected to Confluence!
Found 15 spaces
- FMG: Fraud Model Governance
- CP: Compliance Policies
- FI: Fraud Investigation
...
```
**If you see errors**:
- `401 Unauthorized`: Check your email and API token
- `404 Not Found`: Check your Confluence URL
- `403 Forbidden`: You don't have permission to access Confluence
---
## Step 6: Ingest Confluence Spaces
### Initial Ingestion (One-Time Setup)
This downloads your Confluence content and creates a searchable vector database.
```bash
cd fraud_model_explainability_assistant
python << 'EOF'
from confluence_ingestor import ConfluenceRAG
# Initialize RAG pipeline
print("Initializing Confluence RAG...")
rag = ConfluenceRAG.from_env(
embedding_provider="huggingface",
vector_store_type="chroma"
)
# Ingest spaces (this may take 5-10 minutes)
spaces = {
"fraud-model-governance": 100, # Adjust space keys and limits
"compliance-policies": 50,
"fraud-investigation": 75,
}
for space_key, max_pages in spaces.items():
print(f"\nIngesting {space_key} (max {max_pages} pages)...")
try:
stats = rag.ingest_space(space_key, max_pages=max_pages, force=False)
if stats.get("skipped"):
print(f" β {stats['reason']}")
else:
print(f" β
Ingested {stats['pages']} pages")
print(f" Created {stats['chunks']} chunks")
except Exception as e:
print(f" β Error: {e}")
print("\nβ
Ingestion complete!")
print("Vector database saved to: ./chroma_db/")
EOF
```
**Expected Output**:
```
Initializing Confluence RAG...
Downloading model... (first time only, ~400MB)
Ingesting fraud-model-governance (max 100 pages)...
β
Ingested 87 pages
Created 1,245 chunks
Ingesting compliance-policies (max 50 pages)...
β
Ingested 42 pages
Created 628 chunks
β
Ingestion complete!
Vector database saved to: ./chroma_db/
```
**Time**: 5-10 minutes for ~300 pages (first time only)
---
## Step 7: Test the Integration
### Test Search Functionality
```bash
python << 'EOF'
from confluence_ingestor import ConfluenceRAG
rag = ConfluenceRAG.from_env()
# Test search
results = rag.search("fair lending policy synthetic ID", k=3)
print(f"Found {len(results)} results:\n")
for i, result in enumerate(results, 1):
print(f"{i}. {result.title}")
print(f" Space: {result.space_key}")
print(f" Score: {result.score:.4f}")
print(f" Content: {result.content[:150]}...")
print(f" Source: {result.source}\n")
EOF
```
**Expected Output**:
```
Found 3 results:
1. Fair Lending Policy - Synthetic Identity Detection
Space: compliance-policies
Score: 0.8523
Content: Our fair lending policy addresses synthetic identity detection through the following guidelines...
Source: https://yourcompany.atlassian.net/wiki/spaces/CP/pages/12345
2. Model Validation Report - XGBoost v3.2
Space: fraud-model-governance
Score: 0.7891
Content: The model validation for XGBoost v3.2 includes fair lending compliance testing...
Source: https://yourcompany.atlassian.net/wiki/spaces/FMG/pages/67890
3. Investigation Playbook - Synthetic ID Fraud
Space: fraud-investigation
Score: 0.7654
Content: When investigating synthetic identity fraud, follow these procedures...
Source: https://yourcompany.atlassian.net/wiki/spaces/FI/pages/11111
```
---
## Step 8: Run the Enhanced Fraud Assistant
```bash
# Run the Confluence-integrated version
python confluence_integration_example.py
```
**The app will**:
1. Initialize Confluence RAG (reads from `./chroma_db/`)
2. Create the Confluence search tool
3. Add it to the Strands agent
4. Launch the Gradio UI
**Test it**:
1. Open http://localhost:7860
2. Ask: "What does our fair lending policy say about phone type features?"
3. The agent should search Confluence and cite specific policy documents!
---
## Troubleshooting
### Error: "3 validation errors for ConfluenceConfig"
**Cause**: Environment variables not loaded
**Fix**:
```bash
# Check if .env exists
ls -la .env
# If missing, create it from .env.example
cp .env.example .env
# Edit with your credentials
nano .env
# Verify variables are set
python -c "import os; from dotenv import load_dotenv; load_dotenv(); print('URL:', os.getenv('CONFLUENCE_URL'))"
```
### Error: "401 Unauthorized"
**Cause**: Invalid email or API token
**Fix**:
1. Re-generate your API token at https://id.atlassian.com/manage-profile/security/api-tokens
2. Double-check your email is correct
3. Make sure there are no extra spaces in `.env`
### Error: "404 Not Found"
**Cause**: Incorrect Confluence URL
**Fix**:
1. Check your Confluence URL format
2. For Atlassian Cloud: `https://yourcompany.atlassian.net` (no `/wiki` suffix)
3. For Data Center: `https://confluence.yourcompany.com`
### Error: "403 Forbidden"
**Cause**: User doesn't have permission to access Confluence
**Fix**:
1. Log into Confluence with the same email/token
2. Verify you can view the spaces you're trying to ingest
3. Contact your Confluence admin to grant read access
### Error: "Module not found: confluence_ingestor"
**Cause**: Package not installed
**Fix**:
```bash
pip install confluence-ingestor[strands,huggingface,chroma]
```
### Error: "Slow search queries"
**Cause**: Large vector database or slow embeddings
**Fix**:
1. Reduce `max_pages` when ingesting
2. Consider using OpenAI embeddings (faster but costs money)
3. Filter searches to specific spaces
### Error: "Out of disk space"
**Cause**: Vector database and model cache are large
**Fix**:
1. Vector database: ~150 MB per 100 pages
2. HuggingFace model: ~400 MB (one-time)
3. Free up space or use a smaller corpus
---
## Maintenance
### Update Confluence Content (Daily/Weekly)
```bash
# Re-ingest spaces to pick up new content
python << 'EOF'
from confluence_ingestor import ConfluenceRAG
rag = ConfluenceRAG.from_env()
# Force re-ingestion
for space in ["fraud-model-governance", "compliance-policies"]:
print(f"Updating {space}...")
stats = rag.ingest_space(space, max_pages=100, force=True)
print(f" β
Updated {stats['pages']} pages")
EOF
```
### Automated Updates (Optional)
Add to your deployment:
```python
from apscheduler.schedulers.background import BackgroundScheduler
def refresh_confluence():
rag = ConfluenceRAG.from_env()
for space in ["fraud-model-governance", "compliance-policies"]:
rag.ingest_space(space, max_pages=100, force=True)
scheduler = BackgroundScheduler()
scheduler.add_job(refresh_confluence, 'cron', hour=2) # 2 AM daily
scheduler.start()
```
---
## Security Best Practices
### 1. Use a Service Account
Create a dedicated Confluence user:
- Email: `fraud-bot@yourcompany.com`
- Name: "Fraud Model Assistant"
- Purpose: Read-only access to specific spaces
### 2. Limit Permissions
Grant minimal access:
- β
Read access to relevant spaces
- β No write access
- β No admin access
### 3. Secure Credentials
- β
Store in `.env` (never commit to git)
- β
Use environment variables in production
- β
Rotate API tokens regularly
- β Never hard-code credentials
### 4. Add to .gitignore
```bash
# Add to .gitignore
echo ".env" >> .gitignore
echo "chroma_db/" >> .gitignore
echo "*.log" >> .gitignore
```
---
## Next Steps
Once setup is complete:
1. β
Test with simple queries
2. β
Add more Confluence spaces as needed
3. β
Customize space filters for different use cases
4. β
Share with your team
5. β
Monitor usage and performance
6. β
Set up automated updates
---
## Support
### Documentation
- **confluence-ingestor**: See `/confluence-ingestor/README.md`
- **Strands Agents**: https://strandsagents.com/latest/documentation/docs/
### Common Issues
Check `CONFLUENCE_INTEGRATION_ANALYSIS.md` for:
- Architecture details
- Performance optimization
- Advanced configuration
- ROI analysis
---
## Summary Checklist
- [ ] Create Confluence API token
- [ ] Create `.env` file with credentials
- [ ] Install `confluence-ingestor[strands,huggingface,chroma]`
- [ ] Test Confluence connection
- [ ] Identify relevant Confluence spaces
- [ ] Ingest spaces (5-10 minutes)
- [ ] Test search functionality
- [ ] Run enhanced fraud assistant
- [ ] Add to `.gitignore`
- [ ] Share with team
**Estimated Time**: 30-60 minutes (including ingestion)
---
**Need Help?** Check the troubleshooting section or review the detailed analysis in `CONFLUENCE_INTEGRATION_ANALYSIS.md`.
|