langchain-ai / langchain

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

Unable to insert GraphDocuments into Memgraph #25606

Open pthalasta opened 2 months ago

pthalasta commented 2 months ago

Checked other resources

Example Code

graph = MemgraphGraph(url="bolt://localhost:7687", username="", password="")
documents = [Document(page_content="this is test")]
llm_transformer = LLMGraphTransformer(llm=llm) # please define your llm here
graph_documents = llm_transformer.convert_to_graph_documents(documents)
graph.add_graph_documents(
    graph_documents,
    baseEntityLabel=False,
    include_source=False
)

Error Message and Stack Trace (if applicable)

ClientError: {code: Memgraph.ClientError.MemgraphError.MemgraphError} {message: There is no procedure named 'apoc.merge.node'.}

Description

I understand that the community libs covers support for Memgraph database by extending the Neo4j graph class. However, the functions provided by the class methods do not work with Memgraph. For example. add_graph_documents throws multiple errors depending on the parameters set. In the code, setting parameters baseEntityLabel and include_source to False results in the following error

ClientError: {code: Memgraph.ClientError.MemgraphError.MemgraphError} {message: There is no procedure named 'apoc.merge.node'.}

I'm not sure there exists any such procedures for memgraph as per this post on stackoverflow https://stackoverflow.com/questions/75244143/is-there-something-in-memgraph-that-has-the-same-function-as-apoc-in-neo4j

Now, setting just the baseEntityLabel to True will result in the following error

ClientError: {code: Memgraph.ClientError.MemgraphError.MemgraphError} {message: line 1:19 no viable alternative at input 'CREATECONSTRAINTIF'}

setting include_source to True results in the following error

ClientError: {code: Memgraph.ClientError.MemgraphError.MemgraphError} {message: line 1:53 mismatched input 'text' expecting {ADD, ACTIVE, AFTER, ALTER, AT, ANALYZE, ASYNC, AUTH, BAD, BATCH_INTERVAL, BATCH_LIMIT, BATCH_SIZE, BEFORE, BUILD, BOOTSTRAP_SERVERS, CALL, CHECK, CLEAR, CLUSTER, COMMIT, COMMITTED, CONFIG, CONFIGS, CONSUMER_GROUP, COORDINATOR, CREATE_DELETE, CREDENTIALS, CSV, CURRENT, DATA, DISABLE, DO, DELIMITER, DEMOTE, DATABASE, DATABASES, DENY, DIRECTORY, DROP, DUMP, DURABILITY, EDGE, EDGE_TYPES, ENABLE, ENUM, ENUMS, EVERY, EXECUTE, FAILOVER, FOR, FORCE, FOREACH, FREE, FREE_MEMORY, FROM, GLOBAL, GRANT, GRAPH, GRANTS, HEADER, IDENTIFIED, IF, IGNORE, IMPORT, INACTIVE, IN_MEMORY_ANALYTICAL, IN_MEMORY_TRANSACTIONAL, INSTANCE, INSTANCES, ISOLATION, KAFKA, LABELS, LEVEL, LOAD, LOCK, MAIN, MODE, MODULE_READ, MODULE_WRITE, MULTI_DATABASE_EDIT, MULTI_DATABASE_USE, NEXT, NO, NODE_LABELS, NOTHING, OF_TOKEN, ON_DISK_TRANSACTIONAL, NULLIF, PASSWORD, PERIODIC, PORT, PRIVILEGES, PULSAR, READ, READ_FILE, REGISTER, REPLACE, REPLICA, REPLICAS, REPLICATION, RESET, REVOKE, ROLE, ROLES, ROWS, QUOTE, SCHEMA, SERVER, SERVICE_URL, SESSION, SETTING, SETTINGS, SNAPSHOT, START, STATE, STATISTICS, STATS, STATUS, STOP, STORAGE, STORAGE_MODE, STREAM, STREAMS, SYNC, TERMINATE, TIMEOUT, TO, TOPICS, TRANSACTION, TRANSACTION_MANAGEMENT, TRANSACTIONS, TRANSFORM, TRIGGER, TRIGGERS, TTL, UNCOMMITTED, UNLOCK, UNREGISTER, UPDATE, USE, USER, USERS, USING, VALUE, VALUES, VERSION, WEBSOCKET, ALL, AND, ANY, AS, ASC, ASCENDING, ASSERT, BFS, BY, CASE, COALESCE, CONSTRAINT, CONTAINS, COUNT, CREATE, CYPHERNULL, DELETE, DESC, DESCENDING, DETACH, DISTINCT, ELSE, END, ENDS, EXISTS, EXPLAIN, EXTRACT, FALSE, FILTER, IN, INDEX, INFO, IS, KB, KEY, LIMIT, L_SKIP, MATCH, MB, MEMORY, MERGE, NODE, NONE, NOT, ON, OPTIONAL, OR, ORDER, PROCEDURE, PROFILE, QUERY, REDUCE, REMOVE, RETURN, SET, SHOW, SINGLE, STARTS, THEN, TRUE, UNION, UNIQUE, UNLIMITED, UNWIND, WHEN, WHERE, WITH, WSHORTEST, ALLSHORTEST, XOR, YIELD, UnescapedSymbolicName, EscapedSymbolicName}}

Is Memgraph actually supported for usage with LLMGraphTransformer? Since Neo4jGraph can be used, and MemgraphGraph is derived from neo4j, i would expect it to work without any issue. Please let me know how i can use Memgraph with LLMGraphTransformers, if not can we add this support?

System Info

System Information

OS: Darwin OS Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 Python Version: 3.11.9 (main, Apr 2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.1.0.2.5)]

Package Information

langchain_core: 0.2.33 langchain: 0.2.14 langchain_community: 0.2.12 langsmith: 0.1.84 langchain_experimental: 0.0.64 langchain_milvus: 0.1.4 langchain_nvidia_ai_endpoints: 0.2.1 langchain_openai: 0.1.22 langchain_text_splitters: 0.2.2

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.9.3 async-timeout: Installed. No version info available. dataclasses-json: 0.6.7 jsonpatch: 1.33 numpy: 1.25.0 openai: 1.41.1 orjson: 3.10.6 packaging: 24.1 pillow: 10.4.0 pydantic: 2.8.2 pymilvus: 2.4.4 PyYAML: 6.0.1 requests: 2.31.0 scipy: 1.14.0 SQLAlchemy: 1.4.3 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

katarinasupe commented 2 weeks ago

Hi @pthalasta, thank you for reporting this! I am waiting for my PR to be reviewed, and then add_graph_documents will be added to Memgraph.

For more questions, feel free to join Memgraph's Discord server.