Skip to content

Commit cc7d606

Browse files
author
Jicheng Lu
committed
add payload data type
1 parent 9e87cff commit cc7d606

8 files changed

Lines changed: 152 additions & 74 deletions

File tree

src/lib/helpers/enums.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ const knowledgePayloadName = {
123123
};
124124
export const KnowledgePayloadName = Object.freeze(knowledgePayloadName);
125125

126+
const vectorPayloadDataType = {
127+
String: { id: 1, name: 'String' },
128+
Boolean: { id: 2, name: 'Boolean' },
129+
Integer: { id: 3, name: 'Integer' },
130+
Double: { id: 4, name: 'Double' },
131+
Datetime: { id: 5, name: 'Datetime' },
132+
};
133+
export const VectorPayloadDataType = Object.freeze(vectorPayloadDataType);
134+
126135
const vectorDataSource = {
127136
Api: 'api',
128137
User: 'user',

src/lib/scss/custom/pages/_knowledgebase.scss

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,14 @@
258258
display: flex;
259259
flex-direction: column;
260260
gap: 10px;
261-
max-height: 280px;
261+
min-height: 100px;
262+
max-height: 300px;
262263
overflow-y: auto;
263264
scrollbar-width: none;
264265

265266
.payload-item {
266267
display: flex;
267268
gap: 10px;
268-
269-
.payload-item-content {
270-
flex: 0.5;
271-
}
272269
}
273270
}
274271
}

src/lib/services/knowledge-base-service.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,16 @@ export async function getVectorKnowledgePageList(collection, filter) {
6161
/**
6262
* @param {string} collection
6363
* @param {string} text
64-
* @param {string} dataSource
6564
* @param {any} payload
6665
* @returns {Promise<boolean>}
6766
*/
68-
export async function createVectorKnowledgeData(collection, text, dataSource, payload = null) {
67+
export async function createVectorKnowledgeData(collection, text, payload = null) {
6968
const url = replaceUrl(endpoints.vectorKnowledgeCreateUrl, {
7069
collection: collection
7170
});
7271

7372
const request = {
7473
text: text,
75-
data_source: dataSource,
7674
payload: {
7775
...payload,
7876
}
@@ -86,19 +84,17 @@ export async function createVectorKnowledgeData(collection, text, dataSource, pa
8684
* @param {string} id
8785
* @param {string} collection
8886
* @param {string} text
89-
* @param {string} dataSource
9087
* @param {any} payload
9188
* @returns {Promise<boolean>}
9289
*/
93-
export async function updateVectorKnowledgeData(id, collection, text, dataSource, payload = null) {
90+
export async function updateVectorKnowledgeData(id, collection, text, payload = null) {
9491
const url = replaceUrl(endpoints.vectorKnowledgeUpdateUrl, {
9592
collection: collection
9693
});
9794

9895
const request = {
9996
id: id,
10097
text: text,
101-
data_source: dataSource,
10298
payload: {
10399
...payload
104100
}

src/routes/page/knowledge-base/common/search/advanced-search.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<div class="search-item-content line-align-center">
192192
<div class="fw-bold">{'Value'}</div>
193193
</div>
194+
<div style="flex: 0 0 10px;"></div>
194195
</div>
195196
{#each items as item, idx (item.uuid)}
196197
<div class="knowledge-adv-search-item">

src/routes/page/knowledge-base/common/vector-table/vector-item-edit-modal.svelte

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
Row,
1212
Input
1313
} from "@sveltestrap/sveltestrap";
14-
import { KnowledgeCollectionType, KnowledgePayloadName } from "$lib/helpers/enums";
14+
import {
15+
KnowledgeCollectionType,
16+
KnowledgePayloadName,
17+
VectorPayloadDataType
18+
} from "$lib/helpers/enums";
1519
import util from "lodash";
1620
import { v4 as uuidv4 } from 'uuid';
21+
import Select from "$lib/common/Select.svelte";
1722
1823
1924
/** @type {import('$knowledgeTypes').KnowledgeSearchViewModel | null} */
@@ -58,11 +63,17 @@
5863
/** @type {() => void} */
5964
export let cancel;
6065
66+
67+
const dataTypeOptions = Object.entries(VectorPayloadDataType).map(([k, v]) => ({
68+
label: v.name.toLowerCase(),
69+
value: v.name
70+
}));
71+
6172
$: isQuestionAnswerCollection = collectionType === KnowledgeCollectionType.QuestionAnswer;
6273
$: isDocumentCollection = collectionType === KnowledgeCollectionType.Document;
6374
$: disableConfirmBtn = !util.trim(question.text) || (isQuestionAnswerCollection && !util.trim(answer.text));
6475
65-
/** @type {{ uuid: string, key: string, value: string }[]} */
76+
/** @type {{ uuid: string, key: string, value: any }[]} */
6677
let innerPayloads = [];
6778
6879
/** @type {HTMLElement} */
@@ -88,19 +99,23 @@
8899
question = {
89100
...question,
90101
rows: isQuestionAnswerCollection ? 3 : 10,
91-
text: item?.data?.text || item?.data?.question || ''
102+
text: item?.data?.text?.data_value || item?.data?.question?.data_value || ''
92103
};
93104
94105
answer = {
95106
...answer,
96-
text: item?.data?.answer || ''
107+
text: item?.data?.answer?.data_value || ''
97108
};
98109
99110
innerPayloads = Object.keys(item?.data || {}).filter(key => !excludedPayloads.includes(key)).map(key => {
111+
const foundType = dataTypeOptions.find(x => x.value === item?.data[key]?.data_type);
100112
return {
101113
uuid: uuidv4(),
102114
key: key,
103-
value: item?.data[key]
115+
value: {
116+
...item?.data[key] || {},
117+
data_type: foundType?.value
118+
}
104119
};
105120
});
106121
}
@@ -110,7 +125,7 @@
110125
e.preventDefault();
111126
e.stopPropagation();
112127
113-
innerPayloads = [...innerPayloads, { uuid: uuidv4(), key: '', value: ''}];
128+
innerPayloads = [...innerPayloads, { uuid: uuidv4(), key: '', value: { data_value: '' } }];
114129
115130
if (allowPayload && scrollContainer) {
116131
await tick();
@@ -133,8 +148,12 @@
133148
if (found) {
134149
if (key === 'key') {
135150
found.key = e.target.value;
136-
} else if (key === 'value') {
137-
found.value = e.target.value;
151+
} else if (key === 'data_value') {
152+
found.value.data_value = e.target.value;
153+
} else if (key === 'data_type') {
154+
// @ts-ignore
155+
const selectedValues = e?.detail?.selecteds?.map(x => x.value) || [];
156+
found.value.data_type = selectedValues[0] || null;
138157
}
139158
innerPayloads = innerPayloads.map((x, index) => {
140159
return index === idx ? { ...found } : x;
@@ -155,24 +174,29 @@
155174
innerPayloads = [];
156175
}
157176
158-
const validPayloads = innerPayloads.map(x => ({ key: util.trim(x.key), value: util.trim(x.value) }))
159-
.filter(x => !!x.key && !!x.value && !excludedPayloads.includes(x.key));
160-
177+
const validPayloads = innerPayloads.map(x => ({
178+
key: util.trim(x.key),
179+
value: {
180+
data_value: util.trim(x.value.data_value),
181+
data_type: x.value.data_type || `${VectorPayloadDataType.String.id}`
182+
}
183+
})).filter(x => !!x.key && !!x.value.data_value && !excludedPayloads.includes(x.key));
184+
161185
const obj = validPayloads.reduce((acc, cur) => {
162186
// @ts-ignore
163-
acc[cur.key] = cur.value;
187+
acc[cur.key] = {...cur.value}
164188
return acc;
165189
}, {});
166190
167191
const newItem = {
168192
...item,
169193
data: {
170-
...item?.data,
171194
text: question.text,
172195
answer: answer.text
173196
},
174197
payload: obj || {}
175198
};
199+
176200
confirm?.(newItem);
177201
}
178202
@@ -263,27 +287,37 @@
263287
<div class="payload-container" bind:this={scrollContainer}>
264288
{#if innerPayloads.length > 0}
265289
<div class="payload-item">
266-
<div class="payload-item-content fw-bold">{'Name'}</div>
267-
<div class="payload-item-content fw-bold">{'Value'}</div>
268-
<div></div>
290+
<div class="payload-item-content fw-bold" style="flex: 0.4;">{'Name'}</div>
291+
<div class="payload-item-content fw-bold" style="flex: 0.4;">{'Data Value'}</div>
292+
<div class="payload-item-content fw-bold" style="flex: 0.2;">{'Data Type'}</div>
293+
<div style="flex: 0 0 12px;"></div>
269294
</div>
270295
{/if}
271296
{#each innerPayloads as payload, idx (payload.uuid)}
272297
<div class="payload-item">
273-
<div class="payload-item-content line-align-center">
298+
<div class="payload-item-content line-align-center" style="flex: 0.4;">
274299
<Input
275300
type="text"
276301
maxlength={1000}
277302
value={payload.key}
278303
on:input={e => changePayloadItem(e, idx, 'key')}
279304
/>
280305
</div>
281-
<div class="payload-item-content line-align-center">
306+
<div class="payload-item-content line-align-center" style="flex: 0.4;">
282307
<Input
283308
type="text"
284309
maxlength={1000}
285-
value={payload.value}
286-
on:input={e => changePayloadItem(e, idx, 'value')}
310+
value={payload.value.data_value}
311+
on:input={e => changePayloadItem(e, idx, 'data_value')}
312+
/>
313+
</div>
314+
<div class="payload-item-content line-align-center" style="flex: 0.2;">
315+
<Select
316+
tag={'payload-data-type-select'}
317+
placeholder={'Select'}
318+
selectedValues={payload.value.data_type ? [payload.value.data_type] : []}
319+
options={dataTypeOptions}
320+
on:select={e => changePayloadItem(e, idx, 'data_type')}
287321
/>
288322
</div>
289323
<div class="line-align-center" style="flex: 0 0 12px;">
@@ -300,10 +334,7 @@
300334
{/each}
301335
302336
{#if innerPayloads.length < payloadLimit}
303-
<div class="payload-item">
304-
<div class="payload-item-content line-align-center">
305-
<div class="fw-bold">{''}</div>
306-
</div>
337+
<div class="payload-item justify-content-end">
307338
<div class="payload-item-content line-align-center">
308339
<div class="d-flex justify-content-end">
309340
<Button

src/routes/page/knowledge-base/common/vector-table/vector-item.svelte

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import Swal from 'sweetalert2';
66
import Loader from "$lib/common/Loader.svelte";
77
import { KnowledgeCollectionType, KnowledgePayloadName } from "$lib/helpers/enums";
8-
import { splitTextByCase } from "$lib/helpers/utils/common";
98
109
const svelteDispatch = createEventDispatcher();
1110
@@ -80,11 +79,11 @@
8079

8180
<tr in:fly={{ y: -5, duration: 800 }}>
8281
<td class={`knowledge-text-qa ${isDocumentCollection ? 'knowledge-text' : ''}`}>
83-
<div class="ellipsis">{item?.data?.question || item?.data?.text || ''}</div>
82+
<div class="ellipsis">{item?.data?.text?.data_value || item?.data?.question?.data_value || ''}</div>
8483
</td>
8584
{#if isQuestionAnswerCollection}
8685
<td class="knowledge-text-qa">
87-
<div class="ellipsis">{item?.data?.answer || ''}</div>
86+
<div class="ellipsis">{item?.data?.answer?.data_value || ''}</div>
8887
</td>
8988
{/if}
9089
<td class="knowledge-op">
@@ -133,20 +132,20 @@
133132
<div class="wrappable fw-bold text-primary">
134133
{'Question:'}
135134
</div>
136-
<div class="wrappable">{item?.data?.question || item?.data?.text || ''}</div>
135+
<div class="wrappable">{item?.data?.text?.data_value || item?.data?.question?.data_value || ''}</div>
137136
</li>
138137
<li>
139138
<div class="wrappable fw-bold text-primary">
140139
{'Answer:'}
141140
</div>
142-
<div class="wrappable">{item?.data?.answer || ''}</div>
141+
<div class="wrappable">{item?.data?.answer?.data_value || ''}</div>
143142
</li>
144143
{:else if isDocumentCollection}
145144
<li>
146145
<div class="wrappable fw-bold text-primary">
147146
{'Text:'}
148147
</div>
149-
<div class="wrappable">{item?.data?.text || ''}</div>
148+
<div class="wrappable">{item?.data?.text?.data_value || ''}</div>
150149
</li>
151150
{/if}
152151

@@ -155,7 +154,7 @@
155154
<div class="wrappable fw-bold text-primary">
156155
{'Score:'}
157156
</div>
158-
<div class="wrappable">{`${item.score.toFixed(6)}`}</div>
157+
<div class="wrappable">{`${item.score?.toFixed(6)}`}</div>
159158
</li>
160159
{/if}
161160
</ul>
@@ -171,29 +170,35 @@
171170
in:fly={{ y: -5, duration: 300 }}
172171
out:fly={{ y: -5, duration: 200 }}
173172
>
174-
<li class="more-detail-item wrappable">Data id: {item?.id || ''}</li>
175-
{#if item?.data && Object.keys(item.data).length > 0}
173+
<li class="more-detail-item wrappable">
174+
Data point id: {item?.id || ''}
175+
</li>
176+
{#if item?.vector_dimension}
177+
<li class="more-detail-item wrappable">
178+
Vector dimension: {item?.vector_dimension}
179+
</li>
180+
{/if}
181+
{#if item?.data}
176182
{#each Object.keys(item.data) as key, idx (`${key}-${item?.id}`)}
177-
{#if key === KnowledgePayloadName.FileUrl}
183+
{#if (!excludedPayloads.includes(key))}
178184
<li class="more-detail-item wrappable">
179-
<span>File url:</span>
180-
<!-- svelte-ignore a11y-click-events-have-key-events -->
181-
<!-- svelte-ignore a11y-no-static-element-interactions -->
182-
<span
183-
class="link clickable"
184-
on:click={() => window.open(item?.data?.fileUrl)}
185-
>
186-
link
187-
</span>
185+
<span>{key} {`(${item.data[key]?.data_type?.toLowerCase()})`}: </span>
186+
{#if key === KnowledgePayloadName.FileUrl}
187+
<!-- svelte-ignore a11y-click-events-have-key-events -->
188+
<!-- svelte-ignore a11y-no-static-element-interactions -->
189+
<span
190+
class="link clickable"
191+
on:click={() => window.open(item.data[key]?.data_value)}
192+
>
193+
link
194+
</span>
195+
{:else}
196+
<span>{item.data[key]?.data_value}</span>
197+
{/if}
188198
</li>
189-
{:else if (!excludedPayloads.includes(key))}
190-
<li class="more-detail-item wrappable">{key}: {item.data[key]}</li>
191199
{/if}
192200
{/each}
193201
{/if}
194-
{#if item?.vector_dimension}
195-
<li class="more-detail-item wrappable">Vector dimension: {item?.vector_dimension}</li>
196-
{/if}
197202
</ul>
198203
{/if}
199204
{/if}

0 commit comments

Comments
 (0)