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

Page Not Found for MultiQueryRetriever Documentation #1533

Closed
mirzasreza opened this issue Mar 16, 2024 · 3 comments
Closed

Page Not Found for MultiQueryRetriever Documentation #1533

mirzasreza opened this issue Mar 16, 2024 · 3 comments
Labels
bug Something isn't working documentation Improvements or additions to documentation

Comments

@mirzasreza
Copy link

Screenshot (1)

Describe the bug
While browsing the documentation for MultiQueryRetriever I found the link is broken and the page is not found.
https://python.langchain.com/docs/modules/data_connection/retrievers/how_to/MultiQueryRetriever

Copy link

dosubot bot commented Mar 16, 2024

Hey @mirzasreza, nice to see you around here again! Hope you're doing well. 🚀

Thank you for bringing this to our attention. It appears that the link to the MultiQueryRetriever documentation is indeed broken. I've checked the langflow codebase and found that the reference to this documentation is located in the MultiQueryRetrieverComponent class, specifically in the documentation attribute. Here is the source code for your reference.

While I couldn't find a specific reason why the documentation link is broken, or any recent commits or changes in the URL structure that could have caused this, I did find some useful information in the code itself.

The MultiQueryRetrieverComponent is designed to initialize from a Language Learning Model (LLM) using a default template. It generates multiple versions of a given user question to retrieve relevant documents from a vector database. This is intended to help overcome some limitations of distance-based similarity search by providing alternative perspectives on the user question.

Here are some key configuration details:

  • llm: Represents the Language Learning Model to be used.
  • prompt: Defines the template for generating alternative questions.
  • retriever: The retriever component to be used for fetching documents.
  • parser_key: Defaults to "lines", indicating how the output from the LLM should be parsed.

The build method of the MultiQueryRetrieverComponent class is responsible for creating an instance of MultiQueryRetriever. It can operate with or without a custom prompt. If no custom prompt is provided, it defaults to using the configuration specified in the build_config method.

The MultiQueryRetriever is instantiated using the from_llm method, which requires an LLM, a retriever, and optionally a custom prompt and a parser key. This indicates that the MultiQueryRetriever is capable of integrating closely with language models and retrievers to perform its function.

I hope this information is helpful in the absence of the specific documentation page. If you need further clarification, please let me know.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added bug Something isn't working documentation Improvements or additions to documentation labels Mar 16, 2024
@mirzasreza
Copy link
Author

@dosu-bot can you suggest a example workflow for MultiQueryRetriever?

Copy link

dosubot bot commented Mar 16, 2024

Sure, I can provide a practical example of how to use the MultiQueryRetrieverComponent in the LangChain library. Here's how you can initialize it from a Language Learning Model (LLM), generate multiple versions of a user question, retrieve relevant documents from a vector database, and use the build method with or without a custom prompt:

  1. Initialization: First, you need to initialize the MultiQueryRetrieverComponent with a Language Learning Model (LLM) and a retriever that interfaces with a vector database. The build_config method provides a default prompt template for generating multiple versions of a user question.

  2. Custom Prompt (Optional): You can provide a custom prompt if you want to customize how the LLM generates multiple versions of the user question. The custom prompt should follow the structure defined in the build_config method under the "prompt" key.

  3. Building the Component: Use the build method to create an instance of MultiQueryRetriever. You can either use the default prompt or pass a custom prompt along with the LLM and the retriever.

Here's an example code snippet demonstrating these steps:

from langchain.llms import YourCustomLLM  # Assuming you have a custom LLM implementation
from langchain.retrievers import YourVectorRetriever  # Assuming you have a vector database retriever
from langflow.components.retrievers.MultiQueryRetriever import MultiQueryRetrieverComponent

# Initialize your LLM and Retriever
llm = YourCustomLLM(...)
retriever = YourVectorRetriever(...)

# Initialize the MultiQueryRetrieverComponent
multi_query_retriever_component = MultiQueryRetrieverComponent()

# Optionally, define a custom prompt
custom_prompt = {
    "input_variables": ["question"],
    "template": "As an AI, generate 5 different interpretations of the question: {question}",
    "template_format": "f-string",
}

# Build the MultiQueryRetriever with the default prompt
multi_query_retriever_default = multi_query_retriever_component.build(llm=llm, retriever=retriever)

# Or, build the MultiQueryRetriever with a custom prompt
multi_query_retriever_custom = multi_query_retriever_component.build(llm=llm, retriever=retriever, prompt=custom_prompt)

# Now, multi_query_retriever_default or multi_query_retriever_custom can be used to generate multiple versions of a user question
# and retrieve relevant documents from the vector database.

This example demonstrates how to initialize the MultiQueryRetrieverComponent with a Language Learning Model and a retriever, optionally customize the prompt, and then build the component to generate multiple versions of a user question for document retrieval.

The exact structure and format of the default prompt template provided by the build_config method in the MultiQueryRetrieverComponent class are as follows:

{
  "input_variables": ["question"],
  "input_types": {},
  "output_parser": null,
  "partial_variables": {},
  "template": "You are an AI language model assistant. Your task is \nto generate 3 different versions of the given user \nquestion to retrieve relevant documents from a vector database. \nBy generating multiple perspectives on the user question, \nyour goal is to help the user overcome some of the limitations \nof distance-based similarity search. Provide these alternative \nquestions separated by newlines. Original question: {question}",
  "template_format": "f-string",
  "validate_template": false,
  "_type": "prompt"
}

The exact implementation of the build method in the MultiQueryRetrieverComponent class in the LangChain library is as follows:

def build(
    self,
    llm: BaseLLM,
    retriever: BaseRetriever,
    prompt: Optional[PromptTemplate] = None,
    parser_key: str = "lines",
) -> Union[Callable, MultiQueryRetriever]:
    if not prompt:
        return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, parser_key=parser_key)
    else:
        return MultiQueryRetriever.from_llm(llm=llm, retriever=retriever, prompt=prompt, parser_key=parser_key)

You can find more details in the source code of the MultiQueryRetrieverComponent class.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@dosubot dosubot bot added the stale label Jun 15, 2024
@dosubot dosubot bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2024
@dosubot dosubot bot removed the stale label Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant