From e3eec26e6d4587f14968c6afb65f63f1917fd804 Mon Sep 17 00:00:00 2001 From: mayurkumarp Date: Fri, 8 Jul 2022 18:53:25 +0530 Subject: [PATCH] Fixed weaviate client and Search node --- packages/core/src/components/search/Search.ts | 4 +- packages/server/src/systems/searchCorpus.ts | 3 +- packages/server/src/systems/weaviateClient.ts | 38 ++++++------------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/packages/core/src/components/search/Search.ts b/packages/core/src/components/search/Search.ts index 2ae74120f..2764de5af 100644 --- a/packages/core/src/components/search/Search.ts +++ b/packages/core/src/components/search/Search.ts @@ -22,7 +22,7 @@ const info = 'Search is used to do neural search in the search corpus and return a document' type Document = { - keywords: string + title: string description: string } @@ -95,7 +95,7 @@ export class Search extends ThothComponent> { ) if (typeof resp.data === 'object') { documents.push({ - keywords: resp.data.keywords, + title: resp.data.title, description: resp.data.description, }) } diff --git a/packages/server/src/systems/searchCorpus.ts b/packages/server/src/systems/searchCorpus.ts index a760215a8..2a2209ff8 100644 --- a/packages/server/src/systems/searchCorpus.ts +++ b/packages/server/src/systems/searchCorpus.ts @@ -257,8 +257,7 @@ export async function initSearchCorpus(ignoreDotEnv: boolean) { const question = ctx.request.query?.question as string const searchResult = await search(question) - - return (ctx.body = searchResult.description) + return (ctx.body = searchResult) }) router.post('/vector_search', async function (ctx: Koa.Context) { const question = ctx.request.body?.question as string diff --git a/packages/server/src/systems/weaviateClient.ts b/packages/server/src/systems/weaviateClient.ts index 4acf4c7e9..d6bf281fd 100644 --- a/packages/server/src/systems/weaviateClient.ts +++ b/packages/server/src/systems/weaviateClient.ts @@ -8,6 +8,7 @@ import { database } from '../database' import axios from 'axios' import { ClassifierSchema } from '../types' +const DOCUMENTS_CLASS_NAME = 'DataStore' const saved_docs: SearchSchema[] = [] let client: weaviate.client @@ -96,15 +97,10 @@ async function train(data: SearchSchema[]) { continue } - const topic = await classifyText(data[i].description) - if (!topic || topic === undefined || topic.length <= 0) { - continue - } - saved_docs.push(object) const res = await client.data .creator() - .withClassName(topic) + .withClassName(DOCUMENTS_CLASS_NAME) .withProperties(object) .do() @@ -122,15 +118,10 @@ async function train(data: SearchSchema[]) { continue } - const topic = await classifyText(documents[i].description) - if (!topic || topic === undefined || topic.length <= 0) { - continue - } - saved_docs.push(object) const res = await client.data .creator() - .withClassName(topic) + .withClassName(DOCUMENTS_CLASS_NAME) .withProperties(object) .do() console.log(res) @@ -188,15 +179,10 @@ export async function singleTrain(data: SearchSchema) { return } - const topic = await classifyText(object.description) - if (!topic || topic === undefined || topic.length <= 0) { - return - } - saved_docs.push(object) const res = await client.data .creator() - .withClassName(topic) + .withClassName(DOCUMENTS_CLASS_NAME) .withProperties(object) .do() @@ -205,18 +191,16 @@ export async function singleTrain(data: SearchSchema) { export async function search(query: string): SearchSchema { if (!client || client === undefined) { - return { title: '', description: '' } + await initWeaviateClient(false, false) } - const topic = await classifyText(query) - const info = await client.graphql .get() - .withClassName(topic) - .withFields(['title', 'description']) + .withClassName(DOCUMENTS_CLASS_NAME) + .withFields('title description') .withNearText({ concepts: [query], - certainty: 0.7, + certainty: 0.6, }) .do() @@ -228,10 +212,10 @@ export async function search(query: string): SearchSchema { if ( info['data'] && info['data']['Get'] && - info['data']['Get'][topic] && - info['data']['Get'][topic].length > 0 + info['data']['Get'][DOCUMENTS_CLASS_NAME] && + info['data']['Get'][DOCUMENTS_CLASS_NAME].length > 0 ) { - const data = info['data']['Get'][topic][0] + const data = info['data']['Get'][DOCUMENTS_CLASS_NAME][0] return { title: data.title,