// Shared types for Ingestion ↔ Vector ↔ RAG integration

/** Ingestion → Vector: chunk with embedding ready for upsert */
export interface IndexableChunk {
  id: string;
  sourceId: string;
  knowledgeBaseId: string;
  userId: string;
  content: string;
  chunkIndex: number;
  pageNumber?: number;
  sectionTitle?: string;
  tokenCount: number;
  embedding: number[];
}

/** Vector → RAG: search result with source info for citation */
export interface CitationContext {
  chunkId: string;
  sourceId: string;
  sourceTitle: string;
  content: string;
  pageNumber?: number;
  sectionTitle?: string;
  score: number;
}

/** RAG → Vector: search request parameters */
export interface RetrievalRequest {
  queryEmbedding: number[];
  knowledgeBaseId?: string;
  userId?: string;
  topK?: number;
  enableRerank?: boolean;
}

/** RAG → Vector: complete retrieval response */
export interface RetrievalResponse {
  results: CitationContext[];
  queryTimeMs: number;
}

/** Batch upsert result */
export interface BatchUpsertResult {
  upserted: number;
  failed: number;
  errors?: string[];
}

/** Cleanup trigger when import fails or source is deleted */
export interface VectorCleanupRequest {
  sourceId: string;
  reason: 'import_failed' | 'source_deleted' | 'reparse';
}
