Find answers from the community

Updated last week

[Bug]: Azure Search Client does not get ...

https://github.com/run-llama/llama_index/issues/15350

the azure AI search loses its self._search context somehow
L
Z
38 comments
looking at the source code, I really don't understand the issue lol
no matter what I do
I get the error
Plain Text
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/core/instrumentation/dispatcher.py", line 367, in async_wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py", line 114, in _aretrieve
    return await self._aget_nodes_with_embeddings(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/core/indices/vector_store/retrievers/retriever.py", line 187, in _aget_nodes_with_embeddings
    query_result = await self._vector_store.aquery(query, **self._kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/vector_stores/azureaisearch/base.py", line 1211, in aquery
    return await azure_query_result_search.asearch()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/vector_stores/azureaisearch/base.py", line 1479, in asearch
    return await self._acreate_query_result(search_query, vectors)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/zach/github/ict-unibot-be/.venv/lib/python3.11/site-packages/llama_index/vector_stores/azureaisearch/base.py", line 1420, in _acreate_query_result
    results = await self._search_client.search(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'search'
I have set a global, I have set a class-based reference, I have tried re-setting it
I know it works, because I have set up the index using the same credentials
so AzureAISearchVectorStore is totally busted for me right now
In your code, I saw the line search_or_index_client=self.search_client, -- is it possible self.search_client is being reset?
I would not assign that to self if possible
Plain Text
global search_client
search_client = SearchIndexClient(
    endpoint=str(settings.azure_search_endpoint),
    credential=AzureKeyCredential(str(settings.azure_search_key)),
)

# later on

async def setup_vector_stores(self) -> None:
        """Initialize vector stores for different document types."""
        logger.info("Initializing vector stores...")

        # Initialize Azure AI Search client
        global search_client

        # Initialize Azure AI Search for global documents
        logger.info("Initializing Azure AI Search vector store...")
        self.azure_vector_store = AzureAISearchVectorStore(
            index_name="uni-global-knowledge",
            search_or_index_client=search_client,
            embedding_dimensionality=1536,
            id_field_key="id",
            chunk_field_key="content",
            embedding_field_key="embedding",
            metadata_string_field_key="extra_info",
            doc_id_field_key="doc_id",
            filterable_metadata_field_keys=[
                "is_global",
                "is_pinned",
                "user_id",
                "chat_id",
            ],
            index_management=IndexManagement.CREATE_IF_NOT_EXISTS,
        )
that gives the same error 😐
I really don't understand how thats possible... unless its like some weird async context issue
only diff is I'm doing
Plain Text
self.azure_vector_store_index = VectorStoreIndex.from_vector_store(
            vector_store=self.azure_vector_store,
            embed_model=self.embed_model,
            use_async=True,
            show_progress=True,
        )
I tried the async client too, both gave the same error, it seems like somewhere in here it's resetting and idk why, but I can't seem to fix it no matter what I try
Litterally scanning the code, and nowhere is it ever set to None
Plain Text
search_client = AsyncSearchIndexClient(
    endpoint=str(settings.azure_search_endpoint),
    credential=AzureKeyCredential(str(settings.azure_search_key)),
)


You tried that?
yeah, I'll do it again just for S's and G's, but I spent about 45 debugging, trying to get it to work properly, I'll try it one more time rn
okay yeah, that worked, wtf
so apparently global is needed, maybe the azure creds expire
I thiiiink I see the bug. Its only initializing either the async or sync search client under the hood. But in this method, it seems like its calling the sync client inside an async method (which will be none? maybe?)
it would be nice to give it both
I'll attempt a PR. But I can't test it lol
and the Search Index seems like
if we give it a IndexManagement style it prolly doesn't need search index or client, and I'd just use the index personally
and then get the client from the index if they provide that, but it doesn't seem like it can be reversed if they don't provide the name of the table
I think I spotted the issue. PR incoming.
yay! thank you ❀️
ok merged the above, you should be able to pip install -U ... the package

I added an async_search_or_index_client kwarg to the constructor. I recommend passing in both the sync and async
let me know if it works πŸ™
that entire vector store is pretty jank lol
1000+ LOC lmao why
Add a reply
Sign up and join the conversation on Discord