Protokoll #2314

ID2314
Zeitstempel2025-12-21 12:35:28.223300
Clientroot
IP145.224.96.190
Modellclaude-sonnet-4-20250514
Statuscompleted
Tokens2,613 (Input: 1,304, Output: 1,309)
Dauer87 ms
Request-Zeit2025-12-21 12:35:28.223300
Response-Zeit2025-12-21 12:35:28.310761

Request

{
    "event": "PreToolUse",
    "tool_name": "Write",
    "tool_input": {
        "file_path": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Validation\/CollectionValidator.php",
        "content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\Validation;\n\nuse Infrastructure\\Persistence\\CollectionRepository;\n\n\/**\n * Validator for RAG collection compatibility.\n *\n * Ensures that:\n * - Selected collections have compatible vector sizes\n * - Embedding dimensions match collection requirements\n *\n * @package Infrastructure\\Validation\n *\/\nfinal class CollectionValidator\n{\n    public function __construct(\n        private CollectionRepository $repository\n    ) {\n    }\n\n    \/**\n     * Validate that all selected collections have compatible vector sizes.\n     *\n     * Returns ValidationResult with vector_size as data if valid.\n     *\n     * @param array<string> $collectionIds Array of collection_id values\n     *\/\n    public function validateSelection(array $collectionIds): ValidationResult\n    {\n        if (count($collectionIds) === 0) {\n            return ValidationResult::ok();\n        }\n\n        $collections = $this->repository->findByIds($collectionIds);\n\n        \/\/ Check all collections exist\n        $foundIds = array_column($collections, 'collection_id');\n        $missing = array_diff($collectionIds, $foundIds);\n        if (!empty($missing)) {\n            return ValidationResult::error(\n                'Collections nicht gefunden: ' . implode(', ', $missing)\n            );\n        }\n\n        \/\/ Check all have same vector_size\n        $vectorSizes = array_unique(array_column($collections, 'vector_size'));\n\n        if (count($vectorSizes) > 1) {\n            $details = [];\n            foreach ($collections as $col) {\n                $details[] = \"{$col['display_name']}: {$col['vector_size']}d\";\n            }\n            return ValidationResult::error(\n                'Inkompatible Collections: Unterschiedliche Vektorgrößen (' .\n                implode(', ', $details) . ')'\n            );\n        }\n\n        return ValidationResult::ok((int) ($vectorSizes[0] ?? 0));\n    }\n\n    \/**\n     * Validate that an embedding vector matches the expected collection dimension.\n     *\n     * @param string       $collectionId The collection to check against\n     * @param array<float> $embedding    The embedding vector\n     *\/\n    public function validateEmbedding(string $collectionId, array $embedding): ValidationResult\n    {\n        $collection = $this->repository->find($collectionId);\n\n        if ($collection === null) {\n            return ValidationResult::error(\n                \"Collection '$collectionId' nicht gefunden\"\n            );\n        }\n\n        $expectedSize = (int) $collection['vector_size'];\n        $actualSize = count($embedding);\n\n        if ($expectedSize !== $actualSize) {\n            return ValidationResult::error(\n                \"Dimension Mismatch: Collection '{$collection['display_name']}' \" .\n                \"erwartet {$expectedSize}d, Embedding hat {$actualSize}d\"\n            );\n        }\n\n        return ValidationResult::ok();\n    }\n\n    \/**\n     * Validate embedding against multiple collections.\n     *\n     * First validates collection compatibility, then checks embedding dimension.\n     *\n     * @param array<string> $collectionIds Collections to search\n     * @param array<float>  $embedding     The embedding vector\n     *\/\n    public function validateSearchRequest(array $collectionIds, array $embedding): ValidationResult\n    {\n        \/\/ First validate collections are compatible\n        $selectionResult = $this->validateSelection($collectionIds);\n        if (!$selectionResult->isValid()) {\n            return $selectionResult;\n        }\n\n        \/\/ Then check embedding dimension\n        $expectedSize = $selectionResult->getData();\n        if ($expectedSize !== null && $expectedSize > 0) {\n            $actualSize = count($embedding);\n            if ($expectedSize !== $actualSize) {\n                return ValidationResult::error(\n                    \"Embedding hat {$actualSize}d, Collections erwarten {$expectedSize}d\"\n                );\n            }\n        }\n\n        return ValidationResult::ok();\n    }\n\n    \/**\n     * Check if collections exist and are searchable.\n     *\n     * @param array<string> $collectionIds\n     *\/\n    public function validateSearchable(array $collectionIds): ValidationResult\n    {\n        if (empty($collectionIds)) {\n            return ValidationResult::ok();\n        }\n\n        $collections = $this->repository->findByIds($collectionIds);\n\n        foreach ($collections as $col) {\n            if (!$col['is_active']) {\n                return ValidationResult::error(\n                    \"Collection '{$col['display_name']}' ist nicht aktiv\"\n                );\n            }\n            if (!$col['is_searchable']) {\n                return ValidationResult::error(\n                    \"Collection '{$col['display_name']}' ist nicht durchsuchbar\"\n                );\n            }\n        }\n\n        return ValidationResult::ok();\n    }\n}\n"
    }
}

Response

{
    "tool_response": {
        "type": "create",
        "filePath": "\/var\/www\/dev.campus.systemische-tools.de\/src\/Infrastructure\/Validation\/CollectionValidator.php",
        "content": "<?php\n\ndeclare(strict_types=1);\n\nnamespace Infrastructure\\Validation;\n\nuse Infrastructure\\Persistence\\CollectionRepository;\n\n\/**\n * Validator for RAG collection compatibility.\n *\n * Ensures that:\n * - Selected collections have compatible vector sizes\n * - Embedding dimensions match collection requirements\n *\n * @package Infrastructure\\Validation\n *\/\nfinal class CollectionValidator\n{\n    public function __construct(\n        private CollectionRepository $repository\n    ) {\n    }\n\n    \/**\n     * Validate that all selected collections have compatible vector sizes.\n     *\n     * Returns ValidationResult with vector_size as data if valid.\n     *\n     * @param array<string> $collectionIds Array of collection_id values\n     *\/\n    public function validateSelection(array $collectionIds): ValidationResult\n    {\n        if (count($collectionIds) === 0) {\n            return ValidationResult::ok();\n        }\n\n        $collections = $this->repository->findByIds($collectionIds);\n\n        \/\/ Check all collections exist\n        $foundIds = array_column($collections, 'collection_id');\n        $missing = array_diff($collectionIds, $foundIds);\n        if (!empty($missing)) {\n            return ValidationResult::error(\n                'Collections nicht gefunden: ' . implode(', ', $missing)\n            );\n        }\n\n        \/\/ Check all have same vector_size\n        $vectorSizes = array_unique(array_column($collections, 'vector_size'));\n\n        if (count($vectorSizes) > 1) {\n            $details = [];\n            foreach ($collections as $col) {\n                $details[] = \"{$col['display_name']}: {$col['vector_size']}d\";\n            }\n            return ValidationResult::error(\n                'Inkompatible Collections: Unterschiedliche Vektorgrößen (' .\n                implode(', ', $details) . ')'\n            );\n        }\n\n        return ValidationResult::ok((int) ($vectorSizes[0] ?? 0));\n    }\n\n    \/**\n     * Validate that an embedding vector matches the expected collection dimension.\n     *\n     * @param string       $collectionId The collection to check against\n     * @param array<float> $embedding    The embedding vector\n     *\/\n    public function validateEmbedding(string $collectionId, array $embedding): ValidationResult\n    {\n        $collection = $this->repository->find($collectionId);\n\n        if ($collection === null) {\n            return ValidationResult::error(\n                \"Collection '$collectionId' nicht gefunden\"\n            );\n        }\n\n        $expectedSize = (int) $collection['vector_size'];\n        $actualSize = count($embedding);\n\n        if ($expectedSize !== $actualSize) {\n            return ValidationResult::error(\n                \"Dimension Mismatch: Collection '{$collection['display_name']}' \" .\n                \"erwartet {$expectedSize}d, Embedding hat {$actualSize}d\"\n            );\n        }\n\n        return ValidationResult::ok();\n    }\n\n    \/**\n     * Validate embedding against multiple collections.\n     *\n     * First validates collection compatibility, then checks embedding dimension.\n     *\n     * @param array<string> $collectionIds Collections to search\n     * @param array<float>  $embedding     The embedding vector\n     *\/\n    public function validateSearchRequest(array $collectionIds, array $embedding): ValidationResult\n    {\n        \/\/ First validate collections are compatible\n        $selectionResult = $this->validateSelection($collectionIds);\n        if (!$selectionResult->isValid()) {\n            return $selectionResult;\n        }\n\n        \/\/ Then check embedding dimension\n        $expectedSize = $selectionResult->getData();\n        if ($expectedSize !== null && $expectedSize > 0) {\n            $actualSize = count($embedding);\n            if ($expectedSize !== $actualSize) {\n                return ValidationResult::error(\n                    \"Embedding hat {$actualSize}d, Collections erwarten {$expectedSize}d\"\n                );\n            }\n        }\n\n        return ValidationResult::ok();\n    }\n\n    \/**\n     * Check if collections exist and are searchable.\n     *\n     * @param array<string> $collectionIds\n     *\/\n    public function validateSearchable(array $collectionIds): ValidationResult\n    {\n        if (empty($collectionIds)) {\n            return ValidationResult::ok();\n        }\n\n        $collections = $this->repository->findByIds($collectionIds);\n\n        foreach ($collections as $col) {\n            if (!$col['is_active']) {\n                return ValidationResult::error(\n                    \"Collection '{$col['display_name']}' ist nicht aktiv\"\n                );\n            }\n            if (!$col['is_searchable']) {\n                return ValidationResult::error(\n                    \"Collection '{$col['display_name']}' ist nicht durchsuchbar\"\n                );\n            }\n        }\n\n        return ValidationResult::ok();\n    }\n}\n",
        "structuredPatch": [],
        "originalFile": null
    }
}
← Vorheriger Zur Liste Nächster →