Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling graph data with Apache AGE on Azure Database for PostgreSQL flexible server using Langchain fails with the error "access to library 'age' is not allowed". #29466

Open
5 tasks done
akikawa1123 opened this issue Jan 29, 2025 · 0 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@akikawa1123
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

-- Ceate graph at PGFX
SELECT create_graph('my_graph');
	
-- Add nodes
SELECT * FROM cypher('my_graph', $$
    CREATE (n:Person {name: 'Alice', age: 30})
    CREATE (m:Person {name: 'Bob', age: 25})
    CREATE (o:Person {name: 'Charlie', age: 35})
$$) AS (v agtype);
	
-- Add edges
SELECT * FROM cypher('my_graph', $$
    MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}), (c:Person {name: 'Charlie'})
    CREATE (a)-[:FRIEND]->(b), (a)-[:FRIEND]->(c)
$$) AS (v agtype);
from langchain_community.graphs.age_graph import AGEGraph
from langchain_neo4j import GraphCypherQAChain
from langchain_openai import AzureChatOpenAI
import os

os.environ["AZURE_OPENAI_ENDPOINT"] = "https://<endpoint>.openai.azure.com/"
os.environ["AZURE_OPENAI_API_KEY"] = "<apikey>"

conf = {
    "database": "postgres",
    "user": "<user>",
    "password": "<password>",
    "host": "<servername>.postgres.database.azure.com",
    "port": 5432,
}

llm = AzureChatOpenAI(
    azure_deployment="gpt-4o-mini",
    api_version="2024-08-01-preview",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2
)

graph = AGEGraph(graph_name="""my_graph""", conf=conf)
graph.refresh_schema()
print(graph.schema)

chain = GraphCypherQAChain.from_llm(
   llm, graph=graph, verbose=True,allow_dangerous_requests=True
)

result = chain.invoke("Who is Alice's friend?")
print(result)

Error Message and Stack Trace (if applicable)

$ python test.py
Traceback (most recent call last):
File "/langchain_age/test.py", line 26, in
graph = AGEGraph(graph_name="""my_graph""", conf=conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/langchain_age/langchain_age/lib/python3.12/site-packages/langchain_community/graphs/age_graph.py", line 86, in init
with self._get_cursor() as curs:
^^^^^^^^^^^^^^^^^^
File "/langchain_age/langchain_age/lib/python3.12/site-packages/langchain_community/graphs/age_graph.py", line 143, in _get_cursor
cursor.execute("""LOAD 'age';""")
File "/langchain_age/langchain_age/lib/python3.12/site-packages/psycopg2/extras.py", line 312, in execute
return super().execute(query, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.InsufficientPrivilege: access to library "age" is not allowed

Description

I was unable to handle graph data with Apache AGE on Azure Database for PostgreSQL flexible server (PGFX) using Langchain. When I tried to execute it, the following error occurred:

Error: access to library "age" is not allowed

I believe this is because PGFX is a PaaS service and does not grant permissions to the underlying infrastructure 1. Therefore, I commented out the line cursor.execute("""LOAD 'age';""") at line 143 in langchain_community/graphs/age_graph.py. 2

However, this led to an issue where the first execution of age after establishing a connection fails.3

Traceback (most recent call last):
File "/langchain_age/langchain_age/lib/python3.12/site-packages/langchain_community/graphs/age_graph.py", line 627, in query
curs.execute(wrapped_query)
File "/langchain_age/langchain_age/lib/python3.12/site-packages/psycopg2/extras.py", line 312, in execute
return super().execute(query, vars)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.InternalError_: unhandled cypher(cstring) function call
DETAIL: my_graph

To work around this, I modified the code to create and delete an unrelated graph (using create_graph and delete_graph) after executing cursor.execute("""SET search_path = ag_catalog, "$user", public;"""), which made it work.

Could you please consider fixing this issue?

Image

[1] https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/quickstart-create-server?tabs=portal-create-flexible%2Cportal-get-connection%2Cportal-delete-resources
[2] https://python.langchain.com/api_reference/_modules/langchain_community/graphs/age_graph.html#AGEGraph
[3] apache/age#41

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.12.8 (main, Dec 4 2024, 08:54:13) [GCC 9.4.0]

Package Information

langchain_core: 0.3.32
langchain: 0.3.16
langchain_community: 0.3.16
langsmith: 0.3.1
langchain_neo4j: 0.3.0
langchain_openai: 0.3.2
langchain_text_splitters: 0.3.5

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: Installed. No version info available.
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
neo4j: 5.27.0
numpy: 2.2.2
openai: 1.60.2
orjson: 3.10.15
packaging: 24.2
pydantic: 2.10.6
pydantic-settings: 2.7.1
pytest: Installed. No version info available.
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
rich: Installed. No version info available.
SQLAlchemy: 2.0.37
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2
zstandard: 0.23.0

@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant