langchain-ai / langchain

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

Syntax error, incorrect syntax near '{'."} for Azure Cosmos DB No SQL tutorial #25468

Open hepengfe opened 1 month ago

hepengfe commented 1 month ago

Checked other resources

Example Code

Following tutorial here https://python.langchain.com/v0.2/docs/integrations/vectorstores/azure_cosmos_db_no_sql/

After fixing the code as instructed here by adding

cosmos_database_properties={
        "id" : Config.COSMOS_DB_NAME
    }

Another issue occur and the message indicates some syntax error.

Error Message and Stack Trace (if applicable)

page_content='Direct Preference Optimization: Your Language Model is Secretly a Reward Model Rafael Rafailov∗†Archit Sharma∗†Eric Mitchell∗† Stefano Ermon†‡Christopher D. Manning†Chelsea Finn† †Stanford University‡CZ Biohub {rafailov,architsh,eric.mitchell}@cs.stanford.edu Abstract While large-scale unsupervised language models (LMs) learn broad world knowl- edge and some reasoning skills, achieving precise control of their behavior is difficult due to the completely unsupervised nature of their training. Existing methods for gaining such steerability collect human labels of the relative quality of model generations and fine-tune the unsupervised LM to align with these prefer- ences, often with reinforcement learning from human feedback (RLHF). However, RLHF is a complex and often unstable procedure, first fitting a reward model that reflects the human preferences, and then fine-tuning the large unsupervised LM using reinforcement learning to maximize this estimated reward without drifting' metadata={'source': 'https://arxiv.org/pdf/2305.18290', 'page': 0} Traceback (most recent call last): File "/home/pii/adabit/proj/proj/src/db/cosmos_db_langchain.py", line 114, in results = vectorstore.similarity_search(query) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/langchain_community/vectorstores/azure_cosmos_db_no_sql.py", line 338, in similarity_search docs_and_scores = self.similarity_search_with_score( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/langchain_community/vectorstores/azure_cosmos_db_no_sql.py", line 322, in similarity_search_with_score docs_and_scores = self._similarity_search_with_score( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/langchain_community/vectorstores/azure_cosmos_db_no_sql.py", line 298, in _similarity_search_with_score items = list( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/core/paging.py", line 124, in next return next(self._page_iterator) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/core/paging.py", line 76, in next self._response = self._get_next(self.continuation_token) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_query_iterable.py", line 99, in _fetch_next block = self._ex_context.fetch_next_block() File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/execution_dispatcher.py", line 110, in fetch_next_block raise e File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/execution_dispatcher.py", line 102, in fetch_next_block return self._execution_context.fetch_next_block() File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 79, in fetch_next_block self._ensure() File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 64, in _ensure results = self._fetch_next_block() File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 175, in _fetch_next_block return self._fetch_items_helper_with_retries(self._fetch_function) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 147, in _fetch_items_helper_with_retries return _retry_utility.Execute(self._client, self._client._global_endpoint_manager, callback) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_retry_utility.py", line 87, in Execute result = ExecuteFunction(function, *args, kwargs) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_retry_utility.py", line 149, in ExecuteFunction return function(args, kwargs) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 145, in callback return self._fetch_items_helper_no_retries(fetch_function) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 126, in _fetch_items_helper_no_retries (fetched_items, response_headers) = fetch_function(new_options) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_cosmos_client_connection.py", line 1065, in fetch_fn return self.__QueryFeed( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_cosmos_client_connection.py", line 3092, in QueryFeed result, last_response_headers = self.Post(path, request_params, query, req_headers, kwargs) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2811, in __Post return synchronized_request.SynchronizedRequest( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_synchronized_request.py", line 204, in SynchronizedRequest return _retry_utility.Execute( File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_retry_utility.py", line 85, in Execute result = ExecuteFunction(function, global_endpoint_manager, args, kwargs) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_retry_utility.py", line 149, in ExecuteFunction return function(*args, **kwargs) File "/home/pii/miniconda3/envs/proj/lib/python3.9/site-packages/azure/cosmos/_synchronized_request.py", line 155, in _Request raise exceptions.CosmosHttpResponseError(message=data, response=response) azure.cosmos.exceptions.CosmosHttpResponseError: (BadRequest) Message: {"errors":[{"severity":"Error","location":{"start":26,"end":27},"code":"SC1001","message":"Syntax error, incorrect syntax near '{'."}]} ActivityId: 6f7cd23d-76b5-48c0-b125-5359559ef992, Microsoft.Azure.Documents.Common/2.14.0 Code: BadRequest Message: Message: {"errors":[{"severity":"Error","location":{"start":26,"end":27},"code":"SC1001","message":"Syntax error, incorrect syntax near '{'."}]} ActivityId: 6f7cd23d-76b5-48c0-b125-5359559ef992, Microsoft.Azure.Documents.Common/2.14.0

Description

System Info

System Information

OS: Linux OS Version: #93~20.04.1-Ubuntu SMP Wed Sep 6 16:15:40 UTC 2023 Python Version: 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:50:21) [GCC 12.3.0]

Package Information

langchain_core: 0.2.25 langchain: 0.2.12 langchain_community: 0.2.11 langsmith: 0.1.96 langchain_nomic: 0.1.2 langchain_openai: 0.1.20 langchain_text_splitters: 0.2.2 langchainhub: 0.1.20 langgraph: 0.2.3

hepengfe commented 1 month ago

I change the document sources to a list of simple Document instance, and the issue persists. Therefore, I suspect there is something wrong with the cosmos db end.

hepengfe commented 1 month ago

After rolling back to langchain_community==0.2.6, the problem is solved. I checked the latest source code, and the reason is at the query formatting.