import { generateKnowledgeBaseId } from '../utils/id.js';
import { DEFAULT_CHUNKING_CONFIG } from './chunking.js';
import { DefaultIngestionPipeline } from './ingestion.js';
import { DEFAULT_RETRIEVAL_CONFIG, DefaultRetriever } from './retriever.js';
export class DefaultKnowledgeBase {
    id;
    config;
    ingestion;
    retriever;
    scope;
    vectorStore;
    constructor(config, vectorStore, embeddingProvider) {
        this.vectorStore = vectorStore;
        this.id = config.id ?? generateKnowledgeBaseId();
        this.config = { ...config, id: this.id };
        this.scope = {
            tenantId: config.tenantId,
            namespace: config.namespace,
        };
        const chunkingConfig = {
            ...DEFAULT_CHUNKING_CONFIG,
            ...config.chunking,
        };
        const retrievalConfig = {
            ...DEFAULT_RETRIEVAL_CONFIG,
            ...config.retrieval,
        };
        this.ingestion = new DefaultIngestionPipeline(vectorStore, embeddingProvider, chunkingConfig);
        this.retriever = new DefaultRetriever(vectorStore, embeddingProvider, retrievalConfig);
    }
    async ingest(content, metadata = {}) {
        return this.ingestion.ingest(content, metadata, this.scope, this.id);
    }
    async remove(documentId) {
        return this.ingestion.remove(documentId);
    }
    async query(query) {
        return this.retriever.retrieve(query, this.scope, this.id);
    }
    async clear() {
        await this.vectorStore.deleteByKnowledgeBase(this.id, this.scope.tenantId);
    }
}
//# sourceMappingURL=knowledge-base.js.map