Got Multiple Values for Keyword Argument 'k' in as_retriever Function #22969
-
Checked other resources
Commit to Help
Example Codefrom langchain_openai import AzureChatOpenAI
from langchain_openai import AzureOpenAIEmbeddings
from langchain.vectorstores.azuresearch import AzureSearch
from langchain.chains import RetrievalQA
llm = AzureChatOpenAI(deployment_name=aoai_deployment_id, temperature=0)
embeddings = AzureOpenAIEmbeddings(deployment='text-embedding-3-large',
model='text-embedding-3-large',
azure_endpoint='https://cog-openai-od-ed.openai.azure.com',
openai_api_type="azure",
chunk_size=1)
acs = AzureSearch(azure_search_endpoint = endpoint,
azure_search_key = cog_search_api_key,
index_name = index_name,
embedding_function = embeddings.embed_query,
scoring_profiles = [sc],
default_scoring_profile = sc_name)
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever = acs.as_retriever(search_type="similarity",search_kwargs={"filter":filters, "k":8}),
# retriever = acs.as_retriever(search_kwargs={"filters":filters}),
chain_type_kwargs={"prompt": template},
return_source_documents=True) Description
System Info
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@Panegyric0926 Hello there! I'm here to help you with any bugs, questions, or contributions you might have. Let's tackle this together! To resolve the Here's the corrected code: from langchain_openai import AzureChatOpenAI
from langchain_openai import AzureOpenAIEmbeddings
from langchain.vectorstores.azuresearch import AzureSearch
from langchain.chains import RetrievalQA
llm = AzureChatOpenAI(deployment_name=aoai_deployment_id, temperature=0)
embeddings = AzureOpenAIEmbeddings(deployment='text-embedding-3-large',
model='text-embedding-3-large',
azure_endpoint='https://cog-openai-od-ed.openai.azure.com',
openai_api_type="azure",
chunk_size=1)
acs = AzureSearch(azure_search_endpoint=endpoint,
azure_search_key=cog_search_api_key,
index_name=index_name,
embedding_function=embeddings.embed_query,
scoring_profiles=[sc],
default_scoring_profile=sc_name)
qa_chain = RetrievalQA.from_chain_type(
llm,
retriever=acs.as_retriever(search_type="similarity", k=8, search_kwargs={"filter": filters}),
chain_type_kwargs={"prompt": template},
return_source_documents=True
) This modification ensures that the |
Beta Was this translation helpful? Give feedback.
@Panegyric0926 Hello there! I'm here to help you with any bugs, questions, or contributions you might have. Let's tackle this together!
To resolve the
TypeError: langchain_community.vectorstores.azuresearch.AzureSearch.vector_search() got multiple values for keyword argument 'k'
error and ensure that 8 documents are returned, you need to set thek
parameter directly in theas_retriever
function without including it in thesearch_kwargs
.Here's the corrected code: