Commit Graph
16 Commits
Author SHA1 Message Date
jpmschweitzerandClaude Opus 4.5 1a41e5bb80 feat(library-desk): implement Phase 1 service clients and infrastructure
Implements comprehensive service client layer for Library Desk API to support
Librarian AI agent with multi-tenant knowledge management across Neo4j, Qdrant,
Wiki.js, SearXNG, and Ollama.

## Service Clients (src/clients/)
- Neo4j async client with connection pooling and user-scoped labels
- Qdrant vector store with collection-per-user multi-tenancy
- Wiki.js GraphQL API client for page/dossier management
- SearXNG client for web search integration
- Ollama client for text embeddings (nomic-embed-text)

## Core Infrastructure (src/core/)
- Multi-tenancy helpers for user namespace management
  - Wiki.js: path-based namespaces (/users/{user})
  - Neo4j: user-specific labels (User_{User}_Document)
  - Qdrant: collection per user (library_desk_{user})
- Dependency injection with FastAPI Depends and @lru_cache singletons
- Lifecycle management (startup/shutdown) for all service connections

## Background Jobs (src/jobs/)
- Redis-based job manager for long-running operations
- Job status tracking with 24-hour TTL
- Support for queued, processing, completed, failed states

## Configuration
- Updated config.py with Redis DB 4 for library-desk jobs
- Updated docker-compose.yml: REDIS_DB from 2 to 4
- Added pytest and pytest-asyncio to requirements.txt

## Testing
- Unit tests: 25/25 passed (multi-tenancy helpers)
- Integration tests: 12/12 passed (all services verified)
  - Neo4j connection and CRUD operations
  - Qdrant vector operations with 768-dim embeddings
  - Wiki.js GraphQL queries
  - SearXNG web search
  - Job Manager with Redis
  - Dependency injection lifecycle
- pytest.ini configuration with asyncio support

## Health Monitoring
- Real-time service health checks via /health endpoint
- Connection status for all 5 external services
- Graceful degradation for partial service availability

## Architecture
- Follows async/await pattern throughout
- Connection pooling for Neo4j (singleton driver)
- HTTP client lifecycle management (httpx)
- Multi-tenancy enforced at client layer
- Default user: jpmschweitzer

Files changed: 26 files
- 5 new service clients (~1500 lines)
- 2 core modules (~500 lines)
- 1 job manager (~350 lines)
- 3 test files with 37 test cases
- Updated main.py with lifecycle hooks

All services tested and operational. Ready for Phase 2 (routers/services).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 19:09:54 +01:00
jpmschweitzerandClaude Opus 4.5 e886a2f9ba feat(library): deploy Library infrastructure (Neo4j, Wiki.js, Library Desk API)
Implements The Library system - a knowledge management and HybridRAG platform.

**Stack Files:**
- neo4j.yml: Knowledge graph database with APOC plugin
- wiki.yml: Wiki.js for human-facing dossier management
- library-desk.yml: FastAPI coordination service

**Library Desk Service:**
- FastAPI application following best practices
- Pydantic Settings for configuration management
- Bearer token authentication
- Health monitoring endpoints
- Stub endpoints for future HybridRAG implementation

**Features:**
- All services on docker-dataplane network
- Proper healthchecks for all containers
- Neo4j password validation (alphanumeric only)
- Wiki.js healthcheck fixed for IPv4/IPv6 compatibility
- Python 3.12+ with CVE-checked dependencies
- Minor version locking for stability

**Endpoints:**
- Neo4j Browser: http://192.168.86.149:7474
- Wiki.js: http://192.168.86.149:8088
- Library Desk API: http://192.168.86.149:8089
- API Docs: http://192.168.86.149:8089/docs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 17:35:09 +01:00
jpmschweitzer d13635b146 obsolete 2025-12-07 23:20:38 +01:00
jpmschweitzerandClaude Sonnet 4.5 455d16ce8f feat(scheduler): implement core scheduler service
Add hybrid APScheduler + PostgreSQL-based task scheduling system with minute-based execution and priority queue.

Core features:
- Minute-based scheduling with cron-like patterns (-1 = wildcard)
- Priority queue system (1-100, lower = higher priority)
- Concurrent execution (max 5 tasks simultaneously)
- Full REST API for task management (CRUD operations)
- Task execution tracking with audit trail
- API key authentication (Bearer token)
- Health checks and system statistics

Architecture:
- APScheduler runs every minute
- Queries PostgreSQL for tasks scheduled for current minute
- Executes tasks concurrently by priority
- Records execution history in database

Database schema:
- scheduled_tasks: Task definitions/templates
- task_executions: Individual execution records

Technical stack:
- FastAPI for REST API
- APScheduler for scheduling
- PostgreSQL for persistence
- Pydantic for configuration

Endpoints:
- POST/GET/PUT/DELETE /tasks - Task management
- POST /tasks/{name}/trigger - Manual execution
- GET /executions - Execution history
- GET /health - Health check
- GET /stats - System statistics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 23:12:28 +01:00
jpmschweitzerandClaude 78c0fdf6ec fix(core-ai): fix steward agent result access and increase timeout
- Fixed: Change `result.data` to `result.output` (correct PydanticAI API)
- Increased analysis_timeout from 3s to 10s (mistral-nemo needs more time)

**Status:** Steward now initializes correctly but there's a remaining issue
with the async generator merging logic in two_stage_agent.py causing
requests to hang. This needs further investigation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 13:14:20 +01:00
jpmschweitzerandClaude b0ade653fc feat(stack): add SearXNG metasearch engine for AI web search
Deploy SearXNG privacy-focused metasearch engine as infrastructure service
for core-ai web search capabilities.

Changes:
- Add SearXNG Docker Compose stack
  - Image: searxng/searxng:latest
  - Port: 8087 (HTTP API with JSON format)
  - Network: docker-dataplane (shared with core-ai)
  - Storage: Config only at ~/docker-data/searxng
  - Redis integration: DB 5 on redis-shared for result caching
  - Resource limits: 1 CPU, 512MB RAM
  - Health check: /healthz endpoint

Features:
- Aggregates 246+ search engines (Google, Bing, DuckDuckGo, etc.)
- Privacy-first: No tracking, no profiling, no data collection
- Multi-format: HTML (web UI), JSON (API for core-ai)
- Configurable categories: general, it, science, news, images, videos, etc.
- Result caching via Redis (reduces duplicate queries)

Search Categories:
- general: Web search
- it: Programming/technical (StackOverflow, GitHub, documentation)
- science: Academic (arXiv, PubMed, Semantic Scholar)
- news: News articles
- images/videos: Media search
- map: Geographic/location queries

Integration:
- Core-AI web_search tool uses http://searxng:8080/search API
- JSON format enabled for programmatic access
- Timezone: Europe/Amsterdam

Security:
- Dropped all capabilities except essential (CHOWN, SETGID, SETUID)
- No data persistence (privacy by design)
- Internal network only (not exposed via NPM)

Setup:
1. mkdir -p ~/docker-data/searxng
2. docker-compose -f stacks/searxng.yml up -d
3. Verify: curl "http://localhost:8087/search?q=test&format=json"

API Usage:
GET http://searxng:8080/search?q=query&format=json&categories=general

Resource Usage:
- CPU: ~0.2-0.5 cores
- RAM: ~150-300MB
- Disk: ~10-50MB (config only)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:37:14 +01:00
jpmschweitzer 8487b2a366 feat(core-ai): Implement multi-tiered conversation memory
Introduces a comprehensive, multi-tiered memory system to provide conversation history and context for the AI agent. This lays the foundation for more stateful and intelligent interactions.

Key components of this implementation:

- **Multi-Tiered Memory Architecture:**
  - **Tier 1 (Working Memory):** A fast, in-memory buffer (`ConversationBufferMemory`) that holds the most recent turns of a conversation for immediate access.
  - **Tier 3 (Long-Term Memory):** A persistent, semantic search-based memory store using Qdrant (`QdrantConversationMemory`). It stores all conversation turns as vector embeddings, enabling long-term recall and similarity search.

- **Qdrant Integration:**
  - The `qdrant-client` is added to manage collections and perform vector search operations.
  - Each user is assigned a dedicated Qdrant collection for multi-tenancy.

- **Ollama Embedding Client:**
  - A new `OllamaEmbeddingClient` generates text embeddings via the Ollama API, replacing the need for local sentence-transformer models. This significantly reduces the service's dependency footprint.

- **Configuration and Stack Updates:**
  - The `config.py` and `core-ai.yml` stack file are updated with new settings for enabling memory, configuring Qdrant, and specifying the embedding model.

- **Utility and Schema Additions:**
  - New Pydantic schemas (`memory/schemas.py`) define the data structures for conversation turns and memory management.
  - Utility functions (`utils.py`) are added for user ID sanitization and collection naming.

This feature enhances the agent's capabilities by allowing it to maintain context across multiple turns and sessions, leading to more coherent and relevant responses.
2025-11-30 11:35:45 +01:00
jpmschweitzerandClaude 53267e1665 feat(ai): migrate from Google ADK to PydanticAI with working tool calling
Major Changes:
- Replace Google ADK with PydanticAI framework for agent orchestration
- Implement OpenAI-compatible API endpoint for Ollama integration
- Fix streaming response to send deltas instead of cumulative text
- Add /chat/completions route alias for Open-WebUI compatibility
- Enable tool calling with 5 local tools (calculate, date/time utilities)

Architecture:
- Core-AI service: Standalone Python service with PydanticAI agent
- PydanticAI: Uses OpenAI-compatible Ollama API at /v1 endpoint
- Tool Registry: Shared tool system between core-ai and core-api
- Streaming: Fixed async context issues and delta calculation

Verified Working:
 Chat completion (streaming & non-streaming)
 Tool calling with mistral-nemo and mistral-tools models
 Open-WebUI integration via core-ai:8086
 5 tools: calculate, get_current_time, get_current_date, calculate_date_difference, add_days_to_date
 Proper streaming deltas (no repetition)

Technical Details:
- PydanticAI 1.25.0+ with full Ollama support
- Async context manager issue resolved via chunk collection
- Delta calculation: chunk[len(previous):] to extract new content only
- Routes: /v1/chat/completions and /chat/completions (Open-WebUI compat)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 10:31:14 +01:00
jpmschweitzer 0c2c838766 feat(ai): complete Phase 2/3 documentation and memory system improvements
Phase completion and enhancement updates:

## Documentation Added
- Phase 2 completion: Memory system implementation details
- Phase 3 completion: Research capabilities and tool integration
- Session documentation: Model testing, VRAM optimization analysis
- Test results: Comprehensive prompt testing (v1_verbose: 87/100)
- Tool logging implementation guide

## System Prompts
- Added prompts.py with 7 tested variants for A/B testing
- v1_verbose, v2_concise, v3_imperative, v4_minimal, etc.
- Comprehensive testing results for each variant
- Production-ready prompt selection guidance

## Memory System Enhancements
- Multi-tenancy support: Added user_id parameter throughout
- System message filtering: Don't store system messages in history
- Improved conversation turn tracking with user isolation
- Enhanced memory manager for better multi-user support

## AI Controller Improvements
- Better memory integration with user_id support
- Enhanced error handling for memory operations
- Improved token tracking for usage monitoring
- Skip system message storage (part of agent state)

## Portainer Client
- Comprehensive API client (148 lines)
- Stack management and service monitoring
- Container operations with full error handling
- Async support for all operations

## Architecture Documentation
- Updated agent flow diagrams for ADK architecture
- Enhanced core-api README with current setup
- Updated Docker compose stack configuration
- Complete testing and validation documentation
2025-11-26 08:41:44 +01:00
jpmschweitzer 5e734ad27f ai-flow improvement / add langchain 2025-11-23 14:51:19 +01:00
jpmschweitzer cdbc2a5757 update organizr to use postgres-shared instead of sqlite 2025-11-20 12:10:18 +01:00
jpmschweitzer cb428a885d roll back authentik login. removed and restore working state. 2025-11-19 11:42:06 +01:00
jpmschweitzer e8eb2e954c security rework and memory optimilizations. 2025-11-17 08:48:00 +01:00
jpmschweitzer bdecaa8d65 moved documentation to look at the core-api openapi documentation. 2025-11-14 16:49:11 +01:00
jpmschweitzer 2c360e39a5 remove obsolete maintenance scripts (moved into fastapi) 2025-11-14 16:45:34 +01:00
jpmschweitzer 664fe55ff4 ok... ok... I'll add it to git... 2025-11-14 15:31:25 +01:00