AI-powered collateral double-pledge detection service for the Arda Credit platform.
arda-collateral-intel is a dedicated Rust microservice that provides intelligent collateral analysis using:
- Knowledge Graph - SurrealDB-based graph of collateral relationships and deal lifecycle
- AI Detection - Vector embeddings and semantic search for similarity detection
- Deal Lifecycle Awareness - Understanding of "in-use" vs "not-in-use" collateral states
- Event-Driven Architecture - Processes events from arda-credit and publishes detection results
See Technical Specification v2.0 for complete architecture details.
- Double-Pledge Detection: Identifies when similar collateral is pledged to multiple active deals
- Knowledge Graph: Maintains historical context of collateral usage and relationships
- Lifecycle Intelligence: Distinguishes between currently pledged vs. available collateral
- Document Cross-Reference: Analyzes collateral mentions across security agreements
- Rust 1.75 or higher
- SurrealDB 2.0 or higher
- Docker and Docker Compose (for local development)
- Make (optional, for convenience commands)
This project uses Makefile for convenient development commands. All database operations are managed through docker-compose.
-
Clone the repository
git clone https://github.com/ardaglobal/arda-collateral-intel.git cd arda-collateral-intel -
Initial setup (starts database and creates .env file)
make dev-setup
This will:
- Start SurrealDB in Docker
- Copy
.env.exampleto.env(if it doesn't exist) - Wait for database to be ready
-
Configure environment variables
# Edit .env with your settings # For local development, the defaults work out of the box # Update SURREALDB_PASSWORD if you changed it in docker-compose.yml
-
Build and run the service
make run # Or: cargo run -
Verify service is running
curl http://localhost:3010/health curl http://localhost:3010/ready
# Start SurrealDB
make db-up
# Stop SurrealDB
make db-down
# Clean database (removes all data)
make db-clean
# View database logs
make db-logs
# Start database and service together
make dev-start
# Stop all services
make dev-stopFor deployed environments, configure .env to use SurrealDB Cloud:
SURREALDB_URL=wss://proud-galaxy-06d1403t6pqbn8lsiermaos8os.aws-use1.surreal.cloud
SURREALDB_NAMESPACE=dev # or staging, production
SURREALDB_DATABASE=collateral_intel
SURREALDB_USERNAME=your_username
SURREALDB_PASSWORD=your_passwordThe schema is automatically applied on service startup, so no manual migration is needed.
# Build the project
make build
# Run the service
make run
# Run all tests
make test
# Run tests with output
make test-verbose
# Check formatting
make fmt
# Run linter
make lint
# Run all checks (format, lint, test)
make check
# Setup development environment
make dev-setup
# Start database and service
make dev-start# Build the project
cargo build
# Run unit tests
cargo test
# Run integration tests (requires running SurrealDB)
cargo test --test '*' -- --ignored
# Run with logging
RUST_LOG=debug cargo run
# Check code formatting
cargo fmt --check
# Run linter
cargo clippy -- -D warnings
# Build release binary
cargo build --releasedocker build -t arda-collateral-intel:latest .docker run -d \
-p 3010:3010 \
--env-file .env \
--name arda-collateral-intel \
arda-collateral-intel:latestdocker exec arda-collateral-intel curl http://localhost:3010/healthAll configuration is done via environment variables. See .env.example for the complete list.
SURREALDB_PASSWORD- Password for SurrealDB connection
PORT(default: 3010)SIMILARITY_THRESHOLD(default: 0.85)MAX_CONCURRENT_ANALYSES(default: 10)
GET /health- Liveness probe (always returns 200)GET /ready- Readiness probe (checks dependencies)
POST /api/v1/events/collateral- Receive collateral events from arda-creditPOST /api/v1/events/deal- Receive deal events from arda-creditGET /api/v1/collateral/{id}/detection-history- Query detection results
┌─────────────────┐ Events ┌─────────────────┐
│ arda-credit │ ───────────────────────▶│ arda-collateral │
│ (System of │ │ -intel │
│ Record) │◀─────────────────────── │ (Intelligence │
│ │ Detection Results │ Layer) │
└─────────────────┘ └─────────────────┘
│ │
│ PostgreSQL │ SurrealDB
▼ ▼
┌──────────┐ ┌──────────┐
│ Deals │ │Knowledge │
│Collateral│ │ Graph │
└──────────┘ └──────────┘
- ✅ Service scaffold with Axum
- ✅ Health endpoints
- ✅ SurrealDB schema and connection
- ✅ Knowledge graph manager with CRUD operations
- ✅ Docker Compose for local development
- ⏳ Event webhook endpoints
- ⏳ Basic detection pipeline
- Deal status event processing
- Collateral lifecycle state machine
- Smart detection: only alert if BOTH deals active
- arda-ingest API client
- Document-based similarity signals
- Enhanced match scoring
- Embedding cache optimization
- Similarity index for faster lookups
- Detection pattern analysis
# Run all unit tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_health_endpointIntegration tests require a running SurrealDB instance. They use unique test namespaces to avoid conflicts.
# Start local SurrealDB
make db-up
# Run integration tests
cargo test --test database_integration_test -- --ignored
cargo test --test knowledge_graph_test -- --ignored
cargo test --test semantic_similarity_test -- --ignored
# Or run all ignored tests
cargo test -- --ignoredThe integration tests:
- Connect to SurrealDB (defaults to
ws://localhost:8000) - Create unique test namespaces per test
- Apply the full schema
- Test CRUD operations on collateral and deals
- Test graph relationships and queries
- Test lifecycle status management
- Test double-pledge detection scenarios
The semantic_similarity_test.rs suite validates embedding-based similarity matching:
- High Similarity Detection (>0.9) - Validates detection of highly similar collaterals
- Medium Similarity Detection (0.7-0.9) - Tests medium similarity threshold handling
- Low Similarity Filtering (<0.7) - Ensures low similarity items are filtered out
- Missing Embeddings Handling - Tests graceful handling of collaterals without embeddings
- min_similarity Parameter - Validates threshold parameter is respected
- limit Parameter - Tests result pagination/limiting
- Score Ordering - Verifies results are sorted by similarity descending
- Cosine Similarity Accuracy - Unit tests for cosine similarity calculation
- Vector Normalization - Tests embedding vector normalization
- Cross-Type Matching - Tests matching across different collateral types
- Combined Matching - Tests semantic + exact match combinations
- Embedding Cache - Validates cache utilization for performance
# Run only semantic similarity tests
cargo test --test semantic_similarity_test
# Run with database (integration tests)
cargo test --test semantic_similarity_test -- --ignoredSet these environment variables to customize test database connection:
export SURREALDB_URL=ws://localhost:8000
export SURREALDB_USERNAME=root
export SURREALDB_PASSWORD=secret
cargo test -- --ignoredSee helm/arda-collateral-intel/ for Kubernetes deployment configuration.
# Lint Helm chart
helm lint helm/arda-collateral-intel/
# Install to Kubernetes
helm install arda-collateral-intel helm/arda-collateral-intel/ \
--namespace arda \
--create-namespace
# Upgrade deployment
helm upgrade arda-collateral-intel helm/arda-collateral-intel/ \
--namespace arda- Follow the implementation plan in the technical specification
- Run
cargo fmtandcargo clippybefore committing - Add tests for new functionality
- Update documentation as needed
- Technical Specification v2.0
- CLAUDE.md - AI development context
- Arda Credit API Documentation
- Arda Ingest API Documentation
MIT