langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.86k stars 15.36k forks source link

Issue: TypeError: request() got an unexpected keyword argument 'vectors' when using AzureSearchVectorStore #10995

Closed harithzulfaizal closed 8 months ago

harithzulfaizal commented 1 year ago

I'm encountering an error when running the code snippet below. The error doesn't occur when I use AzureCognitiveSearchRetriever as the retriever, but persists with retriever2 = AzureSearchVectorStoreRetriever(vectorstore=vector_store, search_type="hybrid", k=8).

Appreciate the help, thank you!

chain35 = RetrievalQAWithSourcesChain.from_chain_type(
    model, 
    chain_type="stuff", 
    retriever=retriever2,
    chain_type_kwargs=chain_type_kwargs,
    max_tokens_limit=7000,
    reduce_k_below_max_tokens=True,
    return_source_documents=True
    )

with get_openai_callback() as cb:
    answer = chain35({"question": query}, return_only_outputs=True)

Suggestion:

No response

dosubot[bot] commented 1 year ago

🤖

Hello,

Thank you for reaching out with your issue. The error you're encountering is due to the search() method of the SearchClient class from the azure.search.documents package not accepting a parameter named 'vectors'. This is evident from the code in the vector_search_with_score() method in the AzureSearch class.

Here's the relevant code snippet:

results = self.client.search(
    search_text=query,
    vectors=[
        Vector(
            value=np.array(
                self.embedding_function(query), dtype=np.float32
            ).tolist(),
            k=50,
            fields=FIELDS_CONTENT_VECTOR,
        )
    ],
    filter=filters,
    query_type="semantic",
    query_language=self.semantic_query_language,
    semantic_configuration_name=self.semantic_configuration_name,
    query_caption="extractive",
    query_answer="extractive",
    top=k,
)

In this code, self.client is an instance of SearchClient and it's calling the search() method with 'vectors' as a keyword argument, which is not supported by the SearchClient class in the Azure SDK for Python.

To resolve this issue, you need to modify the vector_search_with_score() method to correctly use the search() method of the SearchClient class. However, without the correct documentation or context on how to perform a vector search with the Azure Search SDK, it's not possible to provide a specific code solution. You may need to refer to the Azure Search SDK documentation or contact Azure support for further assistance.

In the context shared, the AzureSearchVectorStoreRetriever class uses the vector_search_with_score() method from the AzureSearch class based on the search_type attribute. The search_type can be "similarity", "hybrid", or "semantic_hybrid". Depending on the search_type, the vector_search_with_score() method, hybrid_search() method, or semantic_hybrid_search() method is used respectively. If the search_type is not one of these, a ValueError is raised.

I hope this helps clarify the issue. If you have any further questions, please don't hesitate to ask.

Best, Dosu

Sources


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.

shavingtonpitsos commented 11 months ago

for me, I got this error in llama_index with a "vector" vs "vectors" mismatch. llama_index calls

        results = self._search_client.search(
            search_text=search_query,
            vectors=vectors, # <------------------------------------
            top=query.similarity_top_k,
            select=select_fields,
            filter=odata_filter,
        )

and the actual azure search client looks like

  def search(
            self,
            search_text: str,
            *,
            include_total_count: Optional[bool] = None,
            facets: Optional[List[str]] = None,
            filter: Optional[str] = None,
            highlight_fields: Optional[str] = None,
            highlight_post_tag: Optional[str] = None,
            highlight_pre_tag: Optional[str] = None,
            minimum_coverage: Optional[float] = None,
            order_by: Optional[List[str]] = None,
            query_type: Optional[Union[str, QueryType]] = None,
            scoring_parameters: Optional[List[str]] = None,
            scoring_profile: Optional[str] = None,
            search_fields: Optional[List[str]] = None,
            search_mode: Optional[Union[str, SearchMode]] = None,
            query_language: Optional[Union[str, QueryLanguage]] = None,
            query_speller: Optional[Union[str, QuerySpellerType]] = None,
            query_answer: Optional[Union[str, QueryAnswerType]] = None,
            query_answer_count: Optional[int] = None,
            query_caption: Optional[Union[str, QueryCaptionType]] = None,
            query_caption_highlight: Optional[bool] = None,
            semantic_fields: Optional[List[str]] = None,
            semantic_configuration_name: Optional[str] = None,
            select: Optional[List[str]] = None,
            skip: Optional[int] = None,
            top: Optional[int] = None,
            scoring_statistics: Optional[Union[str, ScoringStatistics]] = None,
            session_id: Optional[str] = None,
            vector:Optional[Vector] = None, # <---------------------------------------------------------------
            semantic_error_handling: Optional[Union[str, SemanticErrorHandling]] = None,
            semantic_max_wait_in_milliseconds: Optional[int] = None,
            debug: Optional[Union[str, QueryDebugMode]] = None,
            **kwargs: Any) -> SearchItemPaged[Dict]:

I fixed with

# search_client = SearchClient(
#     endpoint=service_endpoint,
#     index_name=index_name,
#     credential=cognitive_search_credential,
# )

class LLamaSearchClient(SearchClient):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)

    def search(self, **kwargs):
        vectors = kwargs.pop('vectors', None)
        return super().search(
            vector=vectors[0],
            **kwargs
        )

search_client = LLamaSearchClient(
    endpoint=service_endpoint,
    index_name=index_name,
    credential=cognitive_search_credential,
)

godspeed