From 10c38499e421caf258dc8fce464bf481b67664e3 Mon Sep 17 00:00:00 2001 From: maxgfr <25312957+maxgfr@users.noreply.github.com> Date: Tue, 25 Jul 2023 19:23:25 +0200 Subject: [PATCH] fix(app): set new as parameter --- .../src/services/embedding.ts | 31 ++++++++++++------- targets/export-elasticsearch/src/type.ts | 1 + 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/targets/export-elasticsearch/src/services/embedding.ts b/targets/export-elasticsearch/src/services/embedding.ts index 246f27d59..6bd1df1ae 100644 --- a/targets/export-elasticsearch/src/services/embedding.ts +++ b/targets/export-elasticsearch/src/services/embedding.ts @@ -47,7 +47,11 @@ export class EmbeddingService { SOURCES.CONTRIBUTIONS, CollectionSlug.CONTRIBUTION + "-generic", (r) => { - return r.document.answers?.generic?.markdown ?? ""; + return ( + r.document.answers?.generic?.text ?? + r.document.answers?.generic?.markdown ?? + "" + ); } ); await this.ingestDocuments( @@ -125,23 +129,27 @@ export class EmbeddingService { async getContributionDocuments(query: string) { // etape 1 : retrouver les 5 meilleurs elements - const collection = await this.client.getOrCreateCollection({ - name: CollectionSlug.CONTRIBUTION + "-generic", - embeddingFunction: this.embedder, - }); - const result = await collection.query({ - queryTexts: [query], - }); + const result = await this.getDocuments( + CollectionSlug.CONTRIBUTION + "-generic", + query + ); // etape 2 : recuperer les parties découpées // etape 3 : filer les infos liées à la cc return result; } async getServicePublicDocuments(query: string): Promise { + return await this.getDocuments(CollectionSlug.SERVICE_PUBLIC, query); + } + + private async getDocuments( + collectionName: string, + query: string + ): Promise { try { const result: ChromaGetResults = []; const collection = await this.client.getOrCreateCollection({ - name: CollectionSlug.SERVICE_PUBLIC, + name: collectionName, embeddingFunction: this.embedder, }); const queryTextsResult = await collection.query({ @@ -167,7 +175,6 @@ export class EmbeddingService { }, }, }); - console.log(queryResult); const ids = queryResult.ids[0]!; const documents = queryResult.documents[0]!; const text: string = documents @@ -196,7 +203,9 @@ export class EmbeddingService { } async countAndPeekContributionDocuments() { - return await this.countAndPeekDocuments(CollectionSlug.CONTRIBUTION); + return await this.countAndPeekDocuments( + CollectionSlug.CONTRIBUTION + "-generic" + ); } async countAndPeekServicePublicDocuments() { diff --git a/targets/export-elasticsearch/src/type.ts b/targets/export-elasticsearch/src/type.ts index 99a7c4ffa..dfbfec8bf 100644 --- a/targets/export-elasticsearch/src/type.ts +++ b/targets/export-elasticsearch/src/type.ts @@ -21,6 +21,7 @@ export interface DocumentRepo { answers?: { generic?: { markdown: string; + text: string; }; conventionAnswer?: { markdown: string;