Skip to content
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

Why does ragchat response returns a metadata array of 5 undefined? #49

Open
enesakar opened this issue Aug 13, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@enesakar
Copy link
Contributor

{
  output: "I'm sorry, but I cannot answer that question based on the provided context and chat history.",
  isStream: false,
  metadata: [ undefined, undefined, undefined, undefined, undefined ],
}
@enesakar enesakar added the bug Something isn't working label Aug 13, 2024
@umutbozdag
Copy link
Contributor

umutbozdag commented Aug 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants