Skip to content

Commit eca8527

Browse files
committed
Refactor Knowledge Base Schema to Fix Type Regression #7300
1 parent bf5b347 commit eca8527

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Ticket: Refactor Knowledge Base Schema to Fix Type Regression
2+
3+
GH ticket id: #7300
4+
5+
**Assignee:** tobiu
6+
**Labels:** `bug`, `regression`, `refactoring`, `ai-tools`
7+
8+
## Description
9+
10+
The AI query tool (`npm run ai:query`) fails for `--type example` because the knowledge base creation script does not correctly assign a high-level `type` to items originating from the `/examples` directory. The current implementation uses `type` to store the specific code construct (`class`, `method`), creating a conflict.
11+
12+
This ticket refactors the knowledge base schema to solve this regression and make the data model more robust.
13+
14+
### Tasks:
15+
16+
1. **Modify `buildScripts/ai/createKnowledgeBase.mjs`:**
17+
- For each chunk generated from the JSDoc output (`all.json`), add a `type` property (`src`, `example`, etc.) based on its source file path.
18+
- Rename the existing `type` property (which currently holds `class`, `method`, etc.) to `kind` to avoid conflicts.
19+
- For non-JSDoc chunks (guides, releases, tickets), ensure they also have both a `type` and a `kind` property (where both can have the same value, e.g., `type: 'guide'`, `kind: 'guide'`).
20+
21+
2. **Verify `buildScripts/ai/queryKnowledgeBase.mjs`:**
22+
- Confirm that the existing query logic, which filters on the `type` property, works correctly with the new schema without modification.

buildScripts/ai/createKnowledgeBase.mjs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import path from 'path';
44
import dotenv from 'dotenv';
55

66
const
7-
cwd = process.cwd(),
8-
insideNeo = process.env.npm_package_name.includes('neo.mjs'),
9-
neoPath = path.resolve(insideNeo ? './' : './node_modules/neo.mjs/');
7+
cwd = process.cwd(),
8+
insideNeo = process.env.npm_package_name.includes('neo.mjs');
109

1110
dotenv.config({
1211
path: insideNeo ? path.resolve(cwd, '.env') : path.resolve(cwd, '../../.env')
@@ -69,19 +68,25 @@ class CreateKnowledgeBase {
6968

7069
apiData.forEach(item => {
7170
const sourceFile = item.meta ? path.join(item.meta.path, item.meta.filename) : 'unknown';
72-
let chunk;
71+
let chunk, type = 'src';
72+
73+
if (sourceFile.includes('/examples/')) {
74+
type = 'example';
75+
}
7376

7477
if (item.kind === 'class') {
7578
chunk = {
76-
type : 'class',
79+
type,
80+
kind : 'class',
7781
name : item.longname,
7882
description: item.comment,
7983
extends : item.augments?.[0], // Capture the parent class
8084
source : sourceFile
8185
};
8286
} else if (item.kind === 'member' && item.memberof) {
8387
chunk = {
84-
type : 'config',
88+
type,
89+
kind : 'config',
8590
className : item.memberof,
8691
name : item.name,
8792
description: item.description,
@@ -90,7 +95,8 @@ class CreateKnowledgeBase {
9095
};
9196
} else if (item.kind === 'function' && item.memberof) {
9297
chunk = {
93-
type : 'method',
98+
type,
99+
kind : 'method',
94100
className : item.memberof,
95101
name : item.name,
96102
description: item.description,
@@ -138,6 +144,7 @@ class CreateKnowledgeBase {
138144
chunkName = `${item.name} - ${heading}`,
139145
chunk = {
140146
type : 'guide',
147+
kind : 'guide',
141148
name : chunkName,
142149
id : item.id,
143150
isBlog : item.parentId === 'Blog',
@@ -153,6 +160,7 @@ class CreateKnowledgeBase {
153160
// If no headings, add the whole file as one chunk
154161
const chunk = {
155162
type : 'guide',
163+
kind : 'guide',
156164
name : item.name,
157165
id : item.id,
158166
isBlog : item.parentId === 'Blog',
@@ -183,6 +191,7 @@ class CreateKnowledgeBase {
183191

184192
const chunk = {
185193
type : 'release',
194+
kind : 'release',
186195
name : chunkName,
187196
content: content,
188197
source : filePath
@@ -217,6 +226,7 @@ class CreateKnowledgeBase {
217226

218227
const chunk = {
219228
type : 'ticket',
229+
kind : 'ticket',
220230
name : chunkName,
221231
content: content,
222232
source : filePath

0 commit comments

Comments
 (0)