You are an AI language model assistant. Your task is to generate 3 different versions of the given user question to retrieve relevant documents from a vector database. By generating multiple perspectives on the user question, your goal is to help the user overcome some of the limitations of distance-based similarity search. Provide these alternative questions separated by newlines. Original question:
prompt_template = """ You are an AI language model assistant. Your task is to generate 3 different versions of the given user question to retrieve relevant documents from a vector database. By generating multiple perspectives on the user question, your goal is to help the user overcome some of the limitations of distance-based similarity search. Provide these alternative questions separated by newlines. Original question: {question} """ prompt = PromptTemplate.from_template(prompt_template)
import numpy as np from langchain.chains.llm import LLMChain from langchain.retrievers.multi_query import LineListOutputParser, MultiQueryRetriever from langchain_community.chat_models.azure_openai import AzureChatOpenAI from langchain_community.chat_models.baidu_qianfan_endpoint import QianfanChatEndpoint from langchain_community.document_loaders.web_base import WebBaseLoader
from langchain_community.embeddings import HuggingFaceEmbeddings, QianfanEmbeddingsEndpoint from langchain_community.retrievers import ElasticSearchBM25Retriever from langchain_community.vectorstores.chroma import Chroma from langchain_community.vectorstores.elasticsearch import ElasticsearchStore from langchain_core.documents import Document from langchain_core.output_parsers import StrOutputParser from langchain_core.prompts import PromptTemplate from typing importList
from langchain.chains import LLMChain from langchain.output_parsers import PydanticOutputParser from langchain.prompts import PromptTemplate from langchain_core.runnables import RunnableLambda from langchain_text_splitters import RecursiveCharacterTextSplitter from pydantic import BaseModel, Field
question = "What are the approaches to Task Decomposition?" unique_docs = retriever_from_llm.get_relevant_documents(query=question) len(unique_docs)
# 拆解 Langchain ,自己实现这个功能 prompt_template = """ You are an AI language model assistant. Your task is to generate five different versions of the given user question to retrieve relevant documents from a vector database. By generating multiple perspectives on the user question, your goal is to help the user overcome some of the limitations of the distance-based similarity search. Provide these alternative questions separated by newlines. Original question: {question} """ prompt = PromptTemplate.from_template(prompt_template)