import { existsSync, mkdir, mkdirSync } from "fs"; import { IVectorDB } from "../../../interfaces/IVectorDB"; import { IDatabase } from "../../../interfaces/vectorDB/IDatabase"; import { LanceDBEmbeddingConfig } from "../../../types/lanceDB"; import { OptionsVectorService } from "../../../types/vector"; import { LanceDBCollection } from "./collection"; import { LanceDBDatabase } from "./database"; import { LanceDBDocument } from "./document"; import { ICollection } from "../../../interfaces/vectorDB/ICollection"; import { IDocument } from "../../../interfaces/vectorDB/IDocument"; export class LanceDBService implements IVectorDB { rootPath: string embeddingConfig?: LanceDBEmbeddingConfig; constructor(options?: OptionsVectorService) { this.rootPath = options?.host || process.env.REAI_LANCEDB_ROOT_PATH || ""; this.embeddingConfig = options?.embedding; if (!this.rootPath) { throw new Error("LanceDB root path is required"); } if (!existsSync(this.rootPath)) { mkdirSync(this.rootPath) } } database(): IDatabase { return new LanceDBDatabase({ rootPath: this.rootPath }) } collection(): ICollection { return new LanceDBCollection({ rootPath: this.rootPath, embedding: this.embeddingConfig }) } document(): IDocument { return new LanceDBDocument({ rootPath: this.rootPath }) } }