Skip to content

Commit e4f36ed

Browse files
committed
Merge remote-tracking branch 'origin/pprados/02-pymupdf' into pprados/02-pymupdf
2 parents 0f654a1 + 7fc01f3 commit e4f36ed

File tree

12 files changed

+189
-71
lines changed

12 files changed

+189
-71
lines changed

.github/scripts/prep_api_docs_build.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,23 @@ def main():
6464
try:
6565
# Load packages configuration
6666
package_yaml = load_packages_yaml()
67-
packages = [
67+
68+
# Clean target directories
69+
clean_target_directories([
6870
p
6971
for p in package_yaml["packages"]
70-
if not p.get("disabled", False)
71-
and p["repo"].startswith("langchain-ai/")
72+
if p["repo"].startswith("langchain-ai/")
7273
and p["repo"] != "langchain-ai/langchain"
73-
]
74-
75-
# Clean target directories
76-
clean_target_directories(packages)
74+
])
7775

7876
# Move libraries to their new locations
79-
move_libraries(packages)
77+
move_libraries([
78+
p
79+
for p in package_yaml["packages"]
80+
if not p.get("disabled", False)
81+
and p["repo"].startswith("langchain-ai/")
82+
and p["repo"] != "langchain-ai/langchain"
83+
])
8084

8185
print("Library sync completed successfully!")
8286

docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
">[openCypher](https://opencypher.org/) is an open-source implementation of Cypher.# Neptune Open Cypher QA Chain\n",
1616
"This QA chain queries Amazon Neptune using openCypher and returns human readable response\n",
1717
"\n",
18-
"LangChain supports both [Neptune Database](https://docs.aws.amazon.com/neptune/latest/userguide/intro.html) and [Neptune Analytics](https://docs.aws.amazon.com/neptune-analytics/latest/userguide/what-is-neptune-analytics.html) with `NeptuneOpenCypherQAChain` \n",
19-
"\n",
18+
"LangChain supports both [Neptune Database](https://docs.aws.amazon.com/neptune/latest/userguide/intro.html) and [Neptune Analytics](https://docs.aws.amazon.com/neptune-analytics/latest/userguide/what-is-neptune-analytics.html) with `create_neptune_opencypher_qa_chain`.\n",
2019
"\n",
2120
"Neptune Database is a serverless graph database designed for optimal scalability and availability. It provides a solution for graph database workloads that need to scale to 100,000 queries per second, Multi-AZ high availability, and multi-Region deployments. You can use Neptune Database for social networking, fraud alerting, and Customer 360 applications.\n",
2221
"\n",
2322
"Neptune Analytics is an analytics database engine that can quickly analyze large amounts of graph data in memory to get insights and find trends. Neptune Analytics is a solution for quickly analyzing existing graph databases or graph datasets stored in a data lake. It uses popular graph analytic algorithms and low-latency analytic queries.\n",
2423
"\n",
24+
"\n",
25+
"\n",
2526
"## Using Neptune Database"
2627
]
2728
},
@@ -31,7 +32,7 @@
3132
"metadata": {},
3233
"outputs": [],
3334
"source": [
34-
"from langchain_community.graphs import NeptuneGraph\n",
35+
"from langchain_aws.graphs import NeptuneGraph\n",
3536
"\n",
3637
"host = \"<neptune-host>\"\n",
3738
"port = 8182\n",
@@ -53,7 +54,7 @@
5354
"metadata": {},
5455
"outputs": [],
5556
"source": [
56-
"from langchain_community.graphs import NeptuneAnalyticsGraph\n",
57+
"from langchain_aws.graphs import NeptuneAnalyticsGraph\n",
5758
"\n",
5859
"graph = NeptuneAnalyticsGraph(graph_identifier=\"<neptune-analytics-graph-id>\")"
5960
]
@@ -62,36 +63,35 @@
6263
"cell_type": "markdown",
6364
"metadata": {},
6465
"source": [
65-
"## Using NeptuneOpenCypherQAChain\n",
66+
"## Using the Neptune openCypher QA Chain\n",
6667
"\n",
67-
"This QA chain queries Neptune graph database using openCypher and returns human readable response."
68+
"This QA chain queries the Neptune graph database using openCypher and returns a human-readable response."
6869
]
6970
},
7071
{
7172
"cell_type": "code",
7273
"execution_count": null,
7374
"metadata": {},
74-
"outputs": [
75-
{
76-
"data": {
77-
"text/plain": [
78-
"'The Austin airport has 98 outgoing routes.'"
79-
]
80-
},
81-
"execution_count": 3,
82-
"metadata": {},
83-
"output_type": "execute_result"
84-
}
85-
],
75+
"outputs": [],
8676
"source": [
87-
"from langchain.chains import NeptuneOpenCypherQAChain\n",
88-
"from langchain_openai import ChatOpenAI\n",
77+
"from langchain_aws import ChatBedrockConverse\n",
78+
"from langchain_aws.chains import create_neptune_opencypher_qa_chain\n",
8979
"\n",
90-
"llm = ChatOpenAI(temperature=0, model=\"gpt-4\")\n",
80+
"MODEL_ID = \"anthropic.claude-3-5-sonnet-20241022-v2:0\"\n",
81+
"llm = ChatBedrockConverse(\n",
82+
" model=MODEL_ID,\n",
83+
" temperature=0,\n",
84+
")\n",
9185
"\n",
92-
"chain = NeptuneOpenCypherQAChain.from_llm(llm=llm, graph=graph)\n",
86+
"chain = create_neptune_opencypher_qa_chain(\n",
87+
" llm=llm,\n",
88+
" graph=graph,\n",
89+
")\n",
9390
"\n",
94-
"chain.invoke(\"how many outgoing routes does the Austin airport have?\")"
91+
"result = chain.invoke(\n",
92+
" {\"query\": \"How many outgoing routes does the Austin airport have?\"}\n",
93+
")\n",
94+
"print(result[\"result\"].content)"
9595
]
9696
}
9797
],

docs/docs/integrations/graphs/amazon_neptune_sparql.ipynb

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"\n",
1616
"\n",
1717
"This example uses a `NeptuneRdfGraph` class that connects with the Neptune database and loads its schema. \n",
18-
"The `NeptuneSparqlQAChain` is used to connect the graph and LLM to ask natural language questions.\n",
18+
"The `create_neptune_sparql_qa_chain` is used to connect the graph and LLM to ask natural language questions.\n",
1919
"\n",
2020
"This notebook demonstrates an example using organizational data.\n",
2121
"\n",
@@ -60,6 +60,11 @@
6060
"STAGE_BUCKET = \"<bucket-name>\""
6161
]
6262
},
63+
{
64+
"cell_type": "markdown",
65+
"metadata": {},
66+
"source": ""
67+
},
6368
{
6469
"cell_type": "code",
6570
"execution_count": null,
@@ -118,7 +123,7 @@
118123
"metadata": {},
119124
"outputs": [],
120125
"source": [
121-
"!pip install --upgrade --quiet langchain langchain-community langchain-aws"
126+
"!pip install --upgrade --quiet langchain-aws"
122127
]
123128
},
124129
{
@@ -238,48 +243,37 @@
238243
"\"\"\""
239244
]
240245
},
246+
{
247+
"cell_type": "markdown",
248+
"metadata": {},
249+
"source": "### Create the Neptune Database RDF Graph"
250+
},
241251
{
242252
"cell_type": "code",
243253
"execution_count": null,
244254
"metadata": {},
245255
"outputs": [],
246256
"source": [
247-
"import boto3\n",
248-
"from langchain_aws import ChatBedrock\n",
249-
"from langchain_community.chains.graph_qa.neptune_sparql import NeptuneSparqlQAChain\n",
250-
"from langchain_community.graphs import NeptuneRdfGraph\n",
257+
"from langchain_aws.graphs import NeptuneRdfGraph\n",
251258
"\n",
252259
"host = \"<your host>\"\n",
253260
"port = 8182 # change if different\n",
254261
"region = \"us-east-1\" # change if different\n",
255262
"graph = NeptuneRdfGraph(host=host, port=port, use_iam_auth=True, region_name=region)\n",
256263
"\n",
257-
"# Optionally change the schema\n",
264+
"# Optionally, change the schema\n",
258265
"# elems = graph.get_schema_elements\n",
259266
"# change elems ...\n",
260-
"# graph.load_schema(elems)\n",
261-
"\n",
262-
"MODEL_ID = \"anthropic.claude-v2\"\n",
263-
"bedrock_client = boto3.client(\"bedrock-runtime\")\n",
264-
"llm = ChatBedrock(model_id=MODEL_ID, client=bedrock_client)\n",
265-
"\n",
266-
"chain = NeptuneSparqlQAChain.from_llm(\n",
267-
" llm=llm,\n",
268-
" graph=graph,\n",
269-
" examples=EXAMPLES,\n",
270-
" verbose=True,\n",
271-
" top_K=10,\n",
272-
" return_intermediate_steps=True,\n",
273-
" return_direct=False,\n",
274-
")"
267+
"# graph.load_schema(elems)"
275268
]
276269
},
277270
{
278271
"cell_type": "markdown",
279272
"metadata": {},
280273
"source": [
281-
"## Ask questions\n",
282-
"Depends on the data we ingested above"
274+
"## Using the Neptune SPARQL QA Chain\n",
275+
"\n",
276+
"This QA chain queries the Neptune graph database using SPARQL and returns a human-readable response."
283277
]
284278
},
285279
{
@@ -288,7 +282,31 @@
288282
"metadata": {},
289283
"outputs": [],
290284
"source": [
291-
"chain.invoke(\"\"\"How many organizations are in the graph\"\"\")"
285+
"from langchain_aws import ChatBedrockConverse\n",
286+
"from langchain_aws.chains import create_neptune_sparql_qa_chain\n",
287+
"\n",
288+
"MODEL_ID = \"anthropic.claude-3-5-sonnet-20241022-v2:0\"\n",
289+
"llm = ChatBedrockConverse(\n",
290+
" model_id=MODEL_ID,\n",
291+
" temperature=0,\n",
292+
")\n",
293+
"\n",
294+
"chain = create_neptune_sparql_qa_chain(\n",
295+
" llm=llm,\n",
296+
" graph=graph,\n",
297+
" examples=EXAMPLES,\n",
298+
")\n",
299+
"\n",
300+
"result = chain.invoke({\"query\": \"How many organizations are in the graph?\"})\n",
301+
"print(result[\"result\"].content)"
302+
]
303+
},
304+
{
305+
"cell_type": "markdown",
306+
"metadata": {},
307+
"source": [
308+
"## Extra questions\n",
309+
"Here are a few more prompts to try on the graph data that was ingested.\n"
292310
]
293311
},
294312
{
@@ -297,7 +315,7 @@
297315
"metadata": {},
298316
"outputs": [],
299317
"source": [
300-
"chain.invoke(\"\"\"Are there any mergers or acquisitions\"\"\")"
318+
"chain.invoke({\"query\": \"Are there any mergers or acquisitions?\"})"
301319
]
302320
},
303321
{
@@ -306,7 +324,7 @@
306324
"metadata": {},
307325
"outputs": [],
308326
"source": [
309-
"chain.invoke(\"\"\"Find organizations\"\"\")"
327+
"chain.invoke({\"query\": \"Find organizations.\"})"
310328
]
311329
},
312330
{
@@ -315,7 +333,7 @@
315333
"metadata": {},
316334
"outputs": [],
317335
"source": [
318-
"chain.invoke(\"\"\"Find sites of MegaSystems or MegaFinancial\"\"\")"
336+
"chain.invoke({\"query\": \"Find sites of MegaSystems or MegaFinancial.\"})"
319337
]
320338
},
321339
{
@@ -324,7 +342,7 @@
324342
"metadata": {},
325343
"outputs": [],
326344
"source": [
327-
"chain.invoke(\"\"\"Find a member who is manager of one or more members.\"\"\")"
345+
"chain.invoke({\"query\": \"Find a member who is a manager of one or more members.\"})"
328346
]
329347
},
330348
{
@@ -333,7 +351,7 @@
333351
"metadata": {},
334352
"outputs": [],
335353
"source": [
336-
"chain.invoke(\"\"\"Find five members and who their manager is.\"\"\")"
354+
"chain.invoke({\"query\": \"Find five members and their managers.\"})"
337355
]
338356
},
339357
{
@@ -343,7 +361,9 @@
343361
"outputs": [],
344362
"source": [
345363
"chain.invoke(\n",
346-
" \"\"\"Find org units or suborganizations of The Mega Group. What are the sites of those units?\"\"\"\n",
364+
" {\n",
365+
" \"query\": \"Find org units or suborganizations of The Mega Group. What are the sites of those units?\"\n",
366+
" }\n",
347367
")"
348368
]
349369
}

docs/docs/integrations/providers/aws.mdx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,34 @@ from langchain_community.chat_message_histories import DynamoDBChatMessageHistor
310310

311311
## Graphs
312312

313+
### Amazon Neptune
314+
315+
>[Amazon Neptune](https://aws.amazon.com/neptune/)
316+
> is a high-performance graph analytics and serverless database for superior scalability and availability.
317+
318+
For the Cypher and SPARQL integrations below, we need to install the `langchain-aws` library.
319+
320+
```bash
321+
pip install langchain-aws
322+
```
323+
313324
### Amazon Neptune with Cypher
314325

315326
See a [usage example](/docs/integrations/graphs/amazon_neptune_open_cypher).
316327

317328
```python
318-
from langchain_community.graphs import NeptuneGraph
319-
from langchain_community.graphs import NeptuneAnalyticsGraph
320-
from langchain_community.chains.graph_qa.neptune_cypher import NeptuneOpenCypherQAChain
329+
from langchain_aws.graphs import NeptuneGraph
330+
from langchain_aws.graphs import NeptuneAnalyticsGraph
331+
from langchain_aws.chains import create_neptune_opencypher_qa_chain
321332
```
322333

323334
### Amazon Neptune with SPARQL
324335

325336
See a [usage example](/docs/integrations/graphs/amazon_neptune_sparql).
326337

327338
```python
328-
from langchain_community.graphs import NeptuneRdfGraph
329-
from langchain_community.chains.graph_qa.neptune_sparql import NeptuneSparqlQAChain
339+
from langchain_aws.graphs import NeptuneRdfGraph
340+
from langchain_aws.chains import create_neptune_sparql_qa_chain
330341
```
331342

332343

docs/docs/integrations/providers/falkordb.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ See a [usage example](/docs/integrations/graphs/falkordb).
2424
```python
2525
from langchain_community.chains.graph_qa.falkordb import FalkorDBQAChain
2626
```
27+
28+
## Memory
29+
30+
See a [usage example](/docs/integrations/memory/falkordb_chat_message_history).
31+
32+
```python
33+
from langchain_falkordb import FalkorDBChatMessageHistory
34+
```

libs/community/langchain_community/chains/graph_qa/neptune_cypher.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from langchain.chains.base import Chain
77
from langchain.chains.llm import LLMChain
88
from langchain.chains.prompt_selector import ConditionalPromptSelector
9+
from langchain_core._api.deprecation import deprecated
910
from langchain_core.callbacks import CallbackManagerForChainRun
1011
from langchain_core.language_models import BaseLanguageModel
1112
from langchain_core.prompts.base import BasePromptTemplate
@@ -82,6 +83,11 @@ def use_simple_prompt(llm: BaseLanguageModel) -> bool:
8283
)
8384

8485

86+
@deprecated(
87+
since="0.3.15",
88+
removal="1.0",
89+
alternative_import="langchain_aws.create_neptune_opencypher_qa_chain",
90+
)
8591
class NeptuneOpenCypherQAChain(Chain):
8692
"""Chain for question-answering against a Neptune graph
8793
by generating openCypher statements.

libs/community/langchain_community/chains/graph_qa/neptune_sparql.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from langchain.chains.base import Chain
1010
from langchain.chains.llm import LLMChain
11+
from langchain_core._api.deprecation import deprecated
1112
from langchain_core.callbacks.manager import CallbackManagerForChainRun
1213
from langchain_core.language_models import BaseLanguageModel
1314
from langchain_core.prompts.base import BasePromptTemplate
@@ -75,6 +76,11 @@ def extract_sparql(query: str) -> str:
7576
return query
7677

7778

79+
@deprecated(
80+
since="0.3.15",
81+
removal="1.0",
82+
alternative_import="langchain_aws.create_neptune_sparql_qa_chain",
83+
)
7884
class NeptuneSparqlQAChain(Chain):
7985
"""Chain for question-answering against a Neptune graph
8086
by generating SPARQL statements.

0 commit comments

Comments
 (0)