fix(KBService): standardize formatting and improve code readability
All checks were successful
GBCI / build (push) Successful in 1m13s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-05-22 20:32:30 -03:00
parent e2382ccddc
commit 2b2ab3a42e
3 changed files with 30 additions and 19 deletions

View file

@ -371,9 +371,20 @@ export class GBDeployer implements IGBDeployer {
vectorStore = await HNSWLib.load(min['vectorStorePath'], embedding);
} catch (e) {
GBLogEx.info(min, `Creating new store...`);
vectorStore = new HNSWLib(embedding, {
space: 'cosine'
});
vectorStore = await HNSWLib.fromTexts(
['This is General Bots.'], // Initial texts (empty)
{}, // Optional metadata
embedding,
{
'space': 'cosine',
} as any
);
const dir = path.dirname(min['vectorStorePath']);
if (!(await GBUtil.exists(dir))) {
fs.mkdir(dir, { recursive: true });
}
await vectorStore.save(min['vectorStorePath']);
}
return vectorStore;
}
@ -483,7 +494,7 @@ export class GBDeployer implements IGBDeployer {
} else {
return [];
}
1
await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line.length > 0) {
const key = line[1];
@ -692,8 +703,7 @@ export class GBDeployer implements IGBDeployer {
if (packageType === '.gbdrive' || packageType === '.gbdata') {
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName, undefined, undefined, true);
}
else
{
else {
await this.downloadFolder(min, path.join('work', `${gbai}`), packageName);
}
}

View file

@ -1062,7 +1062,7 @@ export class KBService implements IGBKBService {
let website = min.core.getParam<string>(min.instance, 'Website', null);
const maxDepth = min.core.getParam<number>(min.instance, 'Website Depth', 1);
const MAX_DOCUMENTS = 15;
const maxDocuments = min.core.getParam<number>(min.instance, ' ', MAX_DOCUMENTS);
const maxDocuments = min.core.getParam<number>(min.instance, 'Website Max Documents', MAX_DOCUMENTS);
const websiteIgnoreUrls = min.core.getParam<[]>(min.instance, 'Website Ignore URLs', null);
GBLogEx.info(min, `Website: ${website}, Max Depth: ${maxDepth}, Website Max Documents: ${maxDocuments}, Ignore URLs: ${websiteIgnoreUrls}`);
@ -1222,7 +1222,7 @@ export class KBService implements IGBKBService {
try {
const document = await this.loadAndSplitFile(file);
const flattenedDocuments = document.reduce((acc, val) => acc.concat(val), []);
// await min['vectorStore'].addDocuments(flattenedDocuments);
await min['vectorStore'].addDocuments(flattenedDocuments);
} catch (error) {
GBLogEx.info(min, `Ignore processing of ${file}. ${GBUtil.toYAML(error)}`);
}

View file

@ -1,5 +1,6 @@
name,value
Website,https://pragmatismo.com.br/
website Max Documents, 2
Answer Mode,document
Theme Color,purple
LLM Provider,openai
1 name value
2 Website https://pragmatismo.com.br/
3 website Max Documents 2
4 Answer Mode document
5 Theme Color purple
6 LLM Provider openai