Add phased knowledge layer: comments and semantic linking pipeline
This commit is contained in:
@@ -158,6 +158,58 @@ export class MeilisearchService {
|
||||
}
|
||||
}
|
||||
|
||||
buildSemanticChunkIndexName(tenantId: string): string {
|
||||
const config = this.getConfig();
|
||||
const prefix = config?.indexPrefix || 'tenant_';
|
||||
return `${prefix}${tenantId}_semantic_chunks`.toLowerCase();
|
||||
}
|
||||
|
||||
async upsertDocuments(indexName: string, documents: Record<string, any>[]): Promise<void> {
|
||||
const config = this.getConfig();
|
||||
if (!config || !Array.isArray(documents) || documents.length === 0) return;
|
||||
|
||||
const url = `${config.host}/indexes/${encodeURIComponent(indexName)}/documents?primaryKey=id`;
|
||||
try {
|
||||
const response = await this.requestJson('POST', url, documents, this.buildHeaders(config));
|
||||
if (!this.isSuccessStatus(response.status)) {
|
||||
this.logger.warn(`Meilisearch document upsert failed for index ${indexName}: ${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.warn(`Meilisearch document upsert failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async searchIndex(
|
||||
indexName: string,
|
||||
query: string,
|
||||
limit = 20,
|
||||
): Promise<{ hits: any[]; total: number }> {
|
||||
const config = this.getConfig();
|
||||
if (!config) return { hits: [], total: 0 };
|
||||
|
||||
const url = `${config.host}/indexes/${encodeURIComponent(indexName)}/search`;
|
||||
try {
|
||||
const response = await this.requestJson(
|
||||
'POST',
|
||||
url,
|
||||
{ q: query, limit },
|
||||
this.buildHeaders(config),
|
||||
);
|
||||
|
||||
if (!this.isSuccessStatus(response.status)) {
|
||||
this.logger.warn(`Meilisearch search failed for index ${indexName}: ${response.status}`);
|
||||
return { hits: [], total: 0 };
|
||||
}
|
||||
|
||||
const hits = Array.isArray(response.body?.hits) ? response.body.hits : [];
|
||||
const total = response.body?.estimatedTotalHits ?? response.body?.nbHits ?? hits.length;
|
||||
return { hits, total };
|
||||
} catch (error) {
|
||||
this.logger.warn(`Meilisearch search failed: ${error.message}`);
|
||||
return { hits: [], total: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
private getConfig(): MeiliConfig | null {
|
||||
const host = process.env.MEILI_HOST || process.env.MEILISEARCH_HOST;
|
||||
if (!host) return null;
|
||||
|
||||
Reference in New Issue
Block a user