Open enesakar opened 2 months ago
Hi @enesakar, I think I found the cause for it:
Problem When no relevant context is found, the retrieval process returns undefined metadata values in the final output.
Possible Fix In the Database class:
if (allValuesUndefined) {
console.error("No answer found in the provided context.");
return []; // Return empty array instead of object with empty metadata
}
In the ContextService class:
return {
formattedContext: await traceable(
(_context: PrepareChatResult) => formatFacts(_context.map(({ data }) => data)),
{
name: "Step: Format",
metadata: { sessionId },
run_type: "tool",
}
)(context),
metadata: context.length > 0 ? context.map(({ metadata }) => metadata) as TMetadata[] : [],
};
Also we can update this place where we return metadata directly, like this:
metadata: metadata.length > 0 ? metadata : [{}],
What do you think about it? @enesakar