UNPKG

@vfarcic/dot-ai

Version:

AI-powered development productivity platform that enhances software development workflows through intelligent automation and AI-driven assistance

164 lines 5.32 kB
/** * Resource Vector Service * * Vector-based storage and retrieval for Kubernetes cluster resources. * Extends BaseVectorService to provide resource-specific operations. * * This service receives resource data from the dot-ai-controller and stores * it in Qdrant for semantic search capabilities. */ import { BaseVectorService } from './base-vector-service'; import { EmbeddingService } from './embedding-service'; /** * Cluster resource data structure * Matches the format sent by dot-ai-controller * Note: ID is constructed by MCP from namespace/apiVersion/kind/name */ export interface ClusterResource { namespace: string; name: string; kind: string; apiVersion: string; apiGroup?: string; labels: Record<string, string>; annotations?: Record<string, string>; createdAt: string; updatedAt: string; } /** * Resource sync request from controller */ export interface ResourceSyncRequest { upserts?: ClusterResource[]; deletes?: string[]; isResync?: boolean; } /** * Result of a sync operation */ export interface SyncResult { upserted: number; deleted: number; failures: Array<{ id: string; error: string; }>; } /** * Simplified resource identifier for tracking changes */ export interface ResourceIdentifier { namespace: string; kind: string; name: string; apiVersion: string; } /** * Result of a diff and sync operation */ export interface DiffSyncResult { inserted: number; updated: number; deleted: number; insertedResources: ResourceIdentifier[]; updatedResources: ResourceIdentifier[]; deletedResources: ResourceIdentifier[]; } /** * Extract API group from apiVersion * e.g., 'apps/v1' -> 'apps', 'v1' -> '' */ export declare function extractApiGroup(apiVersion: string): string; /** * Build embedding text from resource data * Creates a semantic representation for vector search */ export declare function buildEmbeddingText(resource: ClusterResource): string; /** * Generate resource ID from components * Format: namespace:apiVersion:kind:name */ export declare function generateResourceId(namespace: string, apiVersion: string, kind: string, name: string): string; /** * Generate a deterministic UUID from resource ID for Qdrant storage * Qdrant requires UUIDs or positive integers as point IDs * The hash is deterministic so the same resource ID always maps to the same UUID */ export declare function generateResourceUuid(resourceId: string): string; /** * Check if two resources have meaningful differences * Used for resync diff logic */ export declare function hasResourceChanged(existing: ClusterResource, incoming: ClusterResource): boolean; /** * Vector service for storing and searching Kubernetes cluster resources */ export declare class ResourceVectorService extends BaseVectorService<ClusterResource> { constructor(collectionName?: string, embeddingService?: EmbeddingService); /** * Create searchable text from resource data for embedding generation */ protected createSearchText(resource: ClusterResource): string; /** * Extract unique ID from resource data * Always constructs from components and hashes to UUID for Qdrant */ protected extractId(resource: ClusterResource): string; /** * Convert resource to storage payload format */ protected createPayload(resource: ClusterResource): Record<string, unknown>; /** * Convert storage payload back to resource object */ protected payloadToData(payload: Record<string, unknown>): ClusterResource; /** * Store a resource in the vector database */ storeResource(resource: ClusterResource): Promise<void>; /** * Upsert a resource (alias for storeResource for API consistency) */ upsertResource(resource: ClusterResource): Promise<void>; /** * Get a resource by ID * Accepts human-readable ID (namespace:apiVersion:kind:name) and converts to UUID */ getResource(id: string): Promise<ClusterResource | null>; /** * Delete a resource by ID (idempotent - ignores not found) * Accepts human-readable ID (namespace:apiVersion:kind:name) and converts to UUID */ deleteResource(id: string): Promise<void>; /** * Delete all resources (for testing/reset) */ deleteAllResources(): Promise<void>; /** * List all resources */ listResources(): Promise<ClusterResource[]>; /** * Semantic search for resources with optional exact filters * Combines semantic/keyword search with exact field filtering * Returns resources with their similarity scores for relevance ranking */ searchResources(query: string, filters?: { namespace?: string; kind?: string; apiVersion?: string; }, limit?: number, minScore?: number): Promise<Array<{ resource: ClusterResource; score: number; }>>; /** * Build Qdrant filter object from simple filter parameters */ private buildQdrantFilter; /** * Diff incoming resources against Qdrant and sync changes * Used for periodic resync operations */ diffAndSync(incoming: ClusterResource[]): Promise<DiffSyncResult>; } //# sourceMappingURL=resource-vector-service.d.ts.map