Skip to content

Commit

Permalink
[Obs AI Assistant] Improved logging (elastic#176289)
Browse files Browse the repository at this point in the history
Tiny PR to improve debug logs
  • Loading branch information
sorenlouv authored Feb 8, 2024
1 parent 6076d1b commit cf1ae59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FunctionRegistrationParameters } from '.';
import { MessageRole, type Message } from '../../common/types';
import { concatenateChatCompletionChunks } from '../../common/utils/concatenate_chat_completion_chunks';
import type { ObservabilityAIAssistantClient } from '../service/client';
import { RespondFunctionResources } from '../service/types';

export function registerRecallFunction({
client,
Expand Down Expand Up @@ -95,10 +96,6 @@ export function registerRecallFunction({
queries,
});

resources.logger.debug(`Received ${suggestions.length} suggestions`);

resources.logger.debug(JSON.stringify(suggestions, null, 2));

if (suggestions.length === 0) {
return {
content: [] as unknown as Serializable,
Expand All @@ -113,11 +110,9 @@ export function registerRecallFunction({
client,
connectorId,
signal,
resources,
});

resources.logger.debug(`Received ${relevantDocuments.length} relevant documents`);
resources.logger.debug(JSON.stringify(relevantDocuments, null, 2));

return {
content: relevantDocuments as unknown as Serializable,
};
Expand Down Expand Up @@ -177,6 +172,7 @@ async function scoreSuggestions({
client,
connectorId,
signal,
resources,
}: {
suggestions: Awaited<ReturnType<typeof retrieveSuggestions>>;
systemMessage: Message;
Expand All @@ -185,7 +181,10 @@ async function scoreSuggestions({
client: ObservabilityAIAssistantClient;
connectorId: string;
signal: AbortSignal;
resources: RespondFunctionResources;
}) {
resources.logger.debug(`Suggestions: ${JSON.stringify(suggestions, null, 2)}`);

const systemMessageExtension =
dedent(`You have the function called score available to help you inform the user about how relevant you think a given document is to the conversation.
Please give a score between 1 and 7, fractions are allowed.
Expand Down Expand Up @@ -262,6 +261,8 @@ async function scoreSuggestions({
scoreFunctionRequest.message.function_call.arguments
);

resources.logger.debug(`Scores: ${JSON.stringify(scores, null, 2)}`);

if (scores.length === 0) {
return [];
}
Expand All @@ -279,5 +280,10 @@ async function scoreSuggestions({
relevantDocumentIds.includes(suggestion.id)
);

resources.logger.debug(
`Found ${relevantDocumentIds.length} relevant suggestions from the knowledge base. ${scores.length} suggestions were considered in total.`
);
resources.logger.debug(`Relevant documents: ${JSON.stringify(relevantDocuments, null, 2)}`);

return relevantDocuments;
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export class ObservabilityAIAssistantClient {
},
};

this.dependencies.logger.debug(
`Function response: ${JSON.stringify(functionResponseMessage, null, 2)}`
);

nextMessages = nextMessages.concat(functionResponseMessage);

subscriber.next({
Expand Down Expand Up @@ -357,6 +361,8 @@ export class ObservabilityAIAssistantClient {
return await next(nextMessages);
}

this.dependencies.logger.debug(`Conversation: ${JSON.stringify(nextMessages, null, 2)}`);

if (!persist) {
subscriber.complete();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ export class KnowledgeBaseService {
}): Promise<{
entries: RecalledEntry[];
}> => {
this.dependencies.logger.debug(`Recalling entries from KB for queries: "${queries}"`);
const modelId = await this.dependencies.getModelId();

const [documentsFromKb, documentsFromConnectors] = await Promise.all([
Expand Down Expand Up @@ -482,10 +483,9 @@ export class KnowledgeBaseService {
}
}

if (returnedEntries.length <= sortedEntries.length) {
this.dependencies.logger.debug(
`Dropped ${sortedEntries.length - returnedEntries.length} entries because of token limit`
);
const droppedEntries = sortedEntries.length - returnedEntries.length;
if (droppedEntries > 0) {
this.dependencies.logger.info(`Dropped ${droppedEntries} entries because of token limit`);
}

return {
Expand Down

0 comments on commit cf1ae59

Please sign in to comment.