import { Surreal } from 'surrealdb'; /** * Configuration for SurrealDB connection */ export interface SurrealConfig { /** SurrealDB endpoint URL (e.g., 'ws://localhost:8000/rpc') */ endpoint: string; /** Namespace */ namespace: string; /** Database name */ database: string; /** Authentication credentials */ auth?: { username: string; password: string; }; } /** * Vector record to be stored in SurrealDB's unified rag_documents table. * * Document Store records are written to the same `rag_documents` table used by * RAG Sync, with `collection = 'documents'` as the discriminator. Fields that * don't exist as top-level columns on rag_documents (tokens, startLine, * endLine, context, codebaseId) are folded into `metadata`. */ export interface VectorRecord { /** Unique identifier for the vector (format: documentId:chunkIndex) */ id: string; /** Document identifier */ documentId: string; /** Organization identifier for multi-tenancy */ orgId: string; /** Workspace identifier */ workspaceId: string; /** Codebase identifier (stored in metadata.codebaseId) */ codebaseId: string; /** Chunk index */ chunkIndex: number; /** Text content of the chunk */ text: string; /** Vector embedding (768 dimensions for nomic-embed-text) */ embedding: number[]; /** Estimated token count (stored in metadata.tokens) */ tokens: number; /** Starting line number in original document (stored in metadata.startLine) */ startLine: number; /** Ending line number in original document (stored in metadata.endLine) */ endLine: number; /** Contextual information (stored in metadata.context) */ context?: string; /** Additional metadata */ metadata?: Record; /** Timestamp when record was created */ createdAt: Date; } /** * Statistics about indexed code chunks for a codebase. */ export interface CodebaseStats { /** Total number of vector chunks stored */ totalChunks: number; /** Number of unique files indexed */ totalFiles: number; /** ISO timestamp of the most recently updated chunk, or null if empty */ lastUpdated: string | null; } /** * Adapter for interacting with SurrealDB's unified rag_documents table. * * Writes S3 document vectors to the same table used by RAG Sync, enabling * unified vector search across D1 entities and S3 document content. */ export declare class SurrealAdapter { protected db: Surreal; private config; protected connected: boolean; constructor(config: SurrealConfig); /** * Establish connection to SurrealDB. * * By default, runs schema migration after connecting. Pass * `{ migrateOnConnect: false }` for read-only operations (e.g., getStats, * purge) where the schema is guaranteed to already exist — avoids * unnecessary DDL round-trips. */ connect(options?: { migrateOnConnect?: boolean; }): Promise; /** * Close connection to SurrealDB. * No-op if already disconnected — prevents double-close errors from the * underlying surrealdb client when disconnect() is called without a prior * successful connect(). */ disconnect(): Promise; /** * Check if connected to database */ isConnected(): boolean; /** * Apply database schema DDL. * * Uses the unified rag_documents table (shared with RAG Sync). * Most DEFINE statements use IF NOT EXISTS to be safe when RAG Sync * has already created the table. The `metadata` field is the exception: * it uses DEFINE FIELD OVERWRITE to ensure the FLEXIBLE TYPE object * definition is always applied — SurrealDB v2 SCHEMAFULL mode strips * nested fields from a plain `TYPE object`, so FLEXIBLE is required to * preserve metadata sub-fields (codebaseId, language, packageName, etc.). * OVERWRITE is idempotent and safe for concurrent callers. * * Called automatically by connect() unless `{ migrateOnConnect: false }` is * passed. Can also be called explicitly after connecting for cases where * the caller manages migration timing. */ migrate(): Promise; /** * Insert multiple vector chunks into the unified rag_documents table. * * Maps VectorRecord fields to rag_documents columns: * documentId → doc_id * text → content * codebaseId → metadata.codebaseId * tokens → metadata.tokens * startLine → metadata.startLine * endLine → metadata.endLine * context → metadata.context * (new) → collection = 'documents' */ insertChunks(records: VectorRecord[]): Promise; /** * Delete all vectors associated with a document from rag_documents */ deleteByDocumentId(documentId: string): Promise; /** * Vector similarity search within document content */ vectorSearch(options: { queryVector: number[]; workspaceId?: string; limit?: number; minScore?: number; }): Promise; }>>; } //# sourceMappingURL=surreal-adapter.d.ts.map