Skip to content

How can I return the chunks that are being used in the query? #24244

Closed Answered by DiegoCastr00
DiegoCastr00 asked this question in Q&A
Discussion options

You must be logged in to vote

This is the solution to the problem, we do it by modifying this function:

  const answerChain = RunnableMap.from({
    context: retriever,
    question: new RunnablePassthrough(),
  }).assign({
    answer: RunnableSequence.from([
      (input: { context: Document[]; question: string }) => ({
        context: formatDocumentsAsString(input.context),
        question: input.question,
      }),
      ANSWER_PROMPT,
      model,
      new StringOutputParser(),
    ]),
  });

Complete code:

import { ChatOpenAI, OpenAIEmbeddings } from "@langchain/openai";
import { formatDocumentsAsString } from "langchain/util/document";
import { PromptTemplate } from "@langchain/core/prompts";
import {
  Runna…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@DiegoCastr00
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by DiegoCastr00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant