Open vladfeigin opened 1 month ago
I'm also getting this error.
Tested on Mac and Windows. Seems to only happen when I return the AzureSearch object from a function. Have tried Python 11 and 12. Have tried azure-search-documents 14, 15 and 16b
all have this issue.
Exception ignored in: <function AzureSearch.del at 0x11ff76340> Traceback (most recent call last): File "azuresearch.py", line 393, in del File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 765, in get_event_loop_policy File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 758, in _init_event_loop_policy
ImportError: sys.meta_path is None, Python is likely shutting down
Semi related, I also noticed that when I added text, then searched, it would return nothing, as if it didn't await the text upload. There's something funky happening with the async is my guess.
If you instantiate twice, e.g. just do the below class creation, then do the exact same thing but do whatever you want with the second one, it removes the error. Horrible work around but at least it gets rid of the error...
AzureSearch(
azure_search_endpoint=vector_store_address,
azure_search_key=vector_store_password,
index_name=index_name,
embedding_function=embeddings.embed_query,
)
Thank you for sharing. I also tried with the different artifacts versions , the problem is not resolved neither.
Hi @vladfeigin, I am Khushi, a 4th year student at UofT CS. I’m working with my teammates @anushak18, @ashvini8, and @ssumaiyaahmed, who are also 4th year students at UofT CS. We would like to take the initiative to work on this issue and contribute to LangChain. Please let us know if we can help!
Great! Let me know what do you need? I can supply all the details if any is missing here in the issue description.
same issue here I was following official tutorial and in agents it seems like the tool is not called https://python.langchain.com/docs/tutorials/qa_chat_history/ ,
later on, when I use azure retriever, it works for chains, fails for agent, dropping the error
Same issue...
Same issue
Checked other resources
Example Code
Failing code:
import os
loading environment variables from .env file
from dotenv import load_dotenv load_dotenv()
from langchain_community.vectorstores.azuresearch import AzureSearch from langchain_openai import AzureOpenAIEmbeddings
from azure.search.documents.indexes.models import ( ScoringProfile, SearchableField, SearchField, SearchFieldDataType, SimpleField, TextWeights, )
This module is responsible for integration with Azure Search and uses Langchain framework for this
It contains following functions:
search - search for similar documents in Azure Search. return top 5 results
ingest - gets as parameters a list of documents(chunks) and metadata per document and ingests them into Azure Search
Azure Search configuration
AZURE_SEARCH_SERVICE_ENDPOINT = os.getenv("AZURE_SEARCH_SERVICE_ENDPOINT")
AZURE_SEARCH_API_KEY = os.getenv("AZURE_SEARCH_API_KEY")
AZURE_SEARCH_INDEX_NAME = os.getenv("AZURE_SEARCH_INDEX_NAME")
Azure OpenAI configuration
AZURE_OPENAI_KEY = os.getenv("AZURE_OPENAI_KEY")
AZURE_OPENAI_DEPLOYMENT = os.getenv("AZURE_OPENAI_DEPLOYMENT")
AZURE_OPENAI_ENDPOINT = os.getenv("AZURE_OPENAI_ENDPOINT") AZURE_OPENAI_API_VERSION = os.getenv("AZURE_OPENAI_API_VERSION")
initialize AzureOpenAIEmbeddings
embeddings: AzureOpenAIEmbeddings = \ AzureOpenAIEmbeddings(azure_deployment=AZURE_OPENAI_DEPLOYMENT, openai_api_version=AZURE_OPENAI_API_VERSION, azure_endpoint=AZURE_OPENAI_ENDPOINT, api_key=AZURE_OPENAI_KEY)
define search index custom schema
fields = [ SimpleField( name="chunk_id", type=SearchFieldDataType.String, key=True, filterable=True, ), SimpleField( name="parent_id", type=SearchFieldDataType.String, key=True, filterable=True, ), SearchableField( name="chunk", type=SearchFieldDataType.String, searchable=True, ), SearchField( name="text_vector", type=SearchFieldDataType.Collection(SearchFieldDataType.Single), searchable=True, vector_search_dimensions=len(embeddings.embed_query("Text")), vector_search_profile_name="myHnswProfile", ),
Additional field to store the title
]
create Langchain AzureSearch object
vector_search: AzureSearch = \ AzureSearch(azure_search_endpoint=AZURE_SEARCH_SERVICE_ENDPOINT, azure_search_key=AZURE_SEARCH_API_KEY, index_name=AZURE_SEARCH_INDEX_NAME, embedding_function=embeddings.embed_query,
Configure max retries for the Azure client
)
ingest - gets as parameters a list of documents(chunks) and metadata per document and ingests them into Azure Search
TODO - implement async version of ingest
def ingest(documents: list, metadata):
check the input is valid list and non empty if not return exception
def search(query: str, search_type='similarity', top_k=5):
check the input is valid string and non empty if not raise exception
docs = search("Waht is Microsoft's Fabric?", search_type='hybrid', top_k=5)
Error Message and Stack Trace (if applicable)
Exception ignored in: <function AzureSearch.del at 0x123c86020> Traceback (most recent call last): File "/Users/vladfeigin/myprojects/dai-demos/.venv/lib/python3.11/site-packages/langchain_community/vectorstores/azuresearch.py", line 393, in del File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 765, in get_event_loop_policy File "/opt/homebrew/Cellar/python@3.11/3.11.10/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 758, in _init_event_loop_policy ImportError: sys.meta_path is None, Python is likely shutting down
Description
Running AzureSearch , hybrid search. The program executes properly but fails on termination
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies