-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Obs AI Assistant] Add uuid to knowledge base entries to avoid overwriting accidentally #191043
base: main
Are you sure you want to change the base?
Changes from 29 commits
e627b85
ede9593
4f5cb94
bafa18b
14854d2
f6b8303
f88d826
f42f1ec
b718ae5
59a9362
51cb688
51495d2
5fdcc4d
d470e39
fb7370b
c63a8f9
a6d55ed
b3f7d3a
b20bd1b
0f531e4
63b171d
08aa578
ad425be
6da17f3
90b5484
923681c
03e8fe6
9b2cf9b
5ea4ac2
91c84d2
b7d2f8e
1d6beef
fc0a970
0aaf657
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,9 +79,10 @@ export type ConversationUpdateRequest = ConversationRequestBase & { | |
|
||
export interface KnowledgeBaseEntry { | ||
'@timestamp': string; | ||
id: string; | ||
id: string; // unique ID | ||
doc_id?: string; // human readable ID generated by the LLM and used by the LLM to lookup and update existing entries. TODO: rename `doc_id` to `lookup_id` | ||
title?: string; | ||
text: string; | ||
doc_id: string; | ||
confidence: 'low' | 'medium' | 'high'; | ||
is_correction: boolean; | ||
type?: 'user_instruction' | 'contextual'; | ||
|
@@ -94,12 +95,12 @@ export interface KnowledgeBaseEntry { | |
} | ||
|
||
export interface Instruction { | ||
doc_id: string; | ||
id: string; | ||
text: string; | ||
} | ||
|
||
export interface AdHocInstruction { | ||
doc_id?: string; | ||
id?: string; | ||
Comment on lines
-104
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
text: string; | ||
instruction_type: 'user_instruction' | 'application_instruction'; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { KnowledgeBaseType } from '../../common/types'; | ||
import { v4 } from 'uuid'; | ||
import type { FunctionRegistrationParameters } from '.'; | ||
import { KnowledgeBaseEntryRole } from '../../common'; | ||
|
||
|
@@ -14,6 +14,7 @@ export const SUMMARIZE_FUNCTION_NAME = 'summarize'; | |
export function registerSummarizationFunction({ | ||
client, | ||
functions, | ||
resources, | ||
}: FunctionRegistrationParameters) { | ||
functions.registerFunction( | ||
{ | ||
|
@@ -31,7 +32,7 @@ export function registerSummarizationFunction({ | |
id: { | ||
type: 'string', | ||
description: | ||
'An id for the document. This should be a short human-readable keyword field with only alphabetic characters and underscores, that allow you to update it later.', | ||
'A lookup id for the document. This should be a short human-readable keyword field with only alphabetic characters and underscores, that allow you to find and update it later.', | ||
}, | ||
text: { | ||
type: 'string', | ||
|
@@ -62,21 +63,31 @@ export function registerSummarizationFunction({ | |
], | ||
}, | ||
}, | ||
( | ||
{ arguments: { id, text, is_correction: isCorrection, confidence, public: isPublic } }, | ||
async ( | ||
{ arguments: { id: docId, text, is_correction: isCorrection, confidence, public: isPublic } }, | ||
signal | ||
) => { | ||
// The LLM should be able to update an existing entry by providing the same doc_id | ||
// if no existing entry is found, we generate a uuid | ||
const id = await client.getUuidFromDocId(docId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The LLM will (blindly) suggest a doc_id, without any information about existing entries. With the A better approach might be to get rid of |
||
|
||
resources.logger.debug( | ||
id | ||
? `Updating knowledge base entry with id: ${id}, doc_id: ${docId}` | ||
: `Creating new knowledge base entry with doc_id: ${docId}` | ||
); | ||
|
||
return client | ||
.addKnowledgeBaseEntry({ | ||
entry: { | ||
doc_id: id, | ||
role: KnowledgeBaseEntryRole.AssistantSummarization, | ||
id, | ||
id: id ?? v4(), | ||
doc_id: docId, | ||
title: docId, // use doc_id as title for now | ||
text, | ||
is_correction: isCorrection, | ||
type: KnowledgeBaseType.Contextual, | ||
confidence, | ||
public: isPublic, | ||
role: KnowledgeBaseEntryRole.AssistantSummarization, | ||
confidence, | ||
is_correction: isCorrection, | ||
labels: {}, | ||
}, | ||
// signal, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,7 +41,7 @@ const chatCompleteBaseRt = t.type({ | |
]), | ||
instructions: t.array( | ||
t.intersection([ | ||
t.partial({ doc_id: t.string }), | ||
t.partial({ id: t.string }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still possible to overwrite existing instructions by specifying the |
||
t.type({ | ||
text: t.string, | ||
instruction_type: t.union([ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
is globally unique,doc_id
is only unique per user. Multiple entries can be assigned the samedoc_id
if they are created for different users.