Skip to content

Commit

Permalink
Merge branch 'master' into ruff-0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Jan 15, 2025
2 parents 3d2c77d + 5eb4dc5 commit d007dc2
Show file tree
Hide file tree
Showing 49 changed files with 709 additions and 4,586 deletions.
20 changes: 12 additions & 8 deletions .github/scripts/prep_api_docs_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,23 @@ def main():
try:
# Load packages configuration
package_yaml = load_packages_yaml()
packages = [

# Clean target directories
clean_target_directories([
p
for p in package_yaml["packages"]
if not p.get("disabled", False)
and p["repo"].startswith("langchain-ai/")
if p["repo"].startswith("langchain-ai/")
and p["repo"] != "langchain-ai/langchain"
]

# Clean target directories
clean_target_directories(packages)
])

# Move libraries to their new locations
move_libraries(packages)
move_libraries([
p
for p in package_yaml["packages"]
if not p.get("disabled", False)
and p["repo"].startswith("langchain-ai/")
and p["repo"] != "langchain-ai/langchain"
])

print("Library sync completed successfully!")

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/concepts/retrievers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ LangChain has retrievers for many popular lexical search algorithms / engines.
### Vector store

[Vector stores](/docs/concepts/vectorstores/) are a powerful and efficient way to index and retrieve unstructured data.
An vectorstore can be used as a retriever by calling the `as_retriever()` method.
A vectorstore can be used as a retriever by calling the `as_retriever()` method.

```python
vectorstore = MyVectorStore()
Expand Down
46 changes: 23 additions & 23 deletions docs/docs/integrations/graphs/amazon_neptune_open_cypher.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
">[openCypher](https://opencypher.org/) is an open-source implementation of Cypher.# Neptune Open Cypher QA Chain\n",
"This QA chain queries Amazon Neptune using openCypher and returns human readable response\n",
"\n",
"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",
"\n",
"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",
"\n",
"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",
"\n",
"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",
"\n",
"\n",
"\n",
"## Using Neptune Database"
]
},
Expand All @@ -31,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.graphs import NeptuneGraph\n",
"from langchain_aws.graphs import NeptuneGraph\n",
"\n",
"host = \"<neptune-host>\"\n",
"port = 8182\n",
Expand All @@ -53,7 +54,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain_community.graphs import NeptuneAnalyticsGraph\n",
"from langchain_aws.graphs import NeptuneAnalyticsGraph\n",
"\n",
"graph = NeptuneAnalyticsGraph(graph_identifier=\"<neptune-analytics-graph-id>\")"
]
Expand All @@ -62,36 +63,35 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using NeptuneOpenCypherQAChain\n",
"## Using the Neptune openCypher QA Chain\n",
"\n",
"This QA chain queries Neptune graph database using openCypher and returns human readable response."
"This QA chain queries the Neptune graph database using openCypher and returns a human-readable response."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'The Austin airport has 98 outgoing routes.'"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"from langchain.chains import NeptuneOpenCypherQAChain\n",
"from langchain_openai import ChatOpenAI\n",
"from langchain_aws import ChatBedrockConverse\n",
"from langchain_aws.chains import create_neptune_opencypher_qa_chain\n",
"\n",
"llm = ChatOpenAI(temperature=0, model=\"gpt-4\")\n",
"MODEL_ID = \"anthropic.claude-3-5-sonnet-20241022-v2:0\"\n",
"llm = ChatBedrockConverse(\n",
" model=MODEL_ID,\n",
" temperature=0,\n",
")\n",
"\n",
"chain = NeptuneOpenCypherQAChain.from_llm(llm=llm, graph=graph)\n",
"chain = create_neptune_opencypher_qa_chain(\n",
" llm=llm,\n",
" graph=graph,\n",
")\n",
"\n",
"chain.invoke(\"how many outgoing routes does the Austin airport have?\")"
"result = chain.invoke(\n",
" {\"query\": \"How many outgoing routes does the Austin airport have?\"}\n",
")\n",
"print(result[\"result\"].content)"
]
}
],
Expand Down
82 changes: 51 additions & 31 deletions docs/docs/integrations/graphs/amazon_neptune_sparql.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"\n",
"\n",
"This example uses a `NeptuneRdfGraph` class that connects with the Neptune database and loads its schema. \n",
"The `NeptuneSparqlQAChain` is used to connect the graph and LLM to ask natural language questions.\n",
"The `create_neptune_sparql_qa_chain` is used to connect the graph and LLM to ask natural language questions.\n",
"\n",
"This notebook demonstrates an example using organizational data.\n",
"\n",
Expand Down Expand Up @@ -60,6 +60,11 @@
"STAGE_BUCKET = \"<bucket-name>\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": ""
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -118,7 +123,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install --upgrade --quiet langchain langchain-community langchain-aws"
"!pip install --upgrade --quiet langchain-aws"
]
},
{
Expand Down Expand Up @@ -238,48 +243,37 @@
"\"\"\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": "### Create the Neptune Database RDF Graph"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import boto3\n",
"from langchain_aws import ChatBedrock\n",
"from langchain_community.chains.graph_qa.neptune_sparql import NeptuneSparqlQAChain\n",
"from langchain_community.graphs import NeptuneRdfGraph\n",
"from langchain_aws.graphs import NeptuneRdfGraph\n",
"\n",
"host = \"<your host>\"\n",
"port = 8182 # change if different\n",
"region = \"us-east-1\" # change if different\n",
"graph = NeptuneRdfGraph(host=host, port=port, use_iam_auth=True, region_name=region)\n",
"\n",
"# Optionally change the schema\n",
"# Optionally, change the schema\n",
"# elems = graph.get_schema_elements\n",
"# change elems ...\n",
"# graph.load_schema(elems)\n",
"\n",
"MODEL_ID = \"anthropic.claude-v2\"\n",
"bedrock_client = boto3.client(\"bedrock-runtime\")\n",
"llm = ChatBedrock(model_id=MODEL_ID, client=bedrock_client)\n",
"\n",
"chain = NeptuneSparqlQAChain.from_llm(\n",
" llm=llm,\n",
" graph=graph,\n",
" examples=EXAMPLES,\n",
" verbose=True,\n",
" top_K=10,\n",
" return_intermediate_steps=True,\n",
" return_direct=False,\n",
")"
"# graph.load_schema(elems)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ask questions\n",
"Depends on the data we ingested above"
"## Using the Neptune SPARQL QA Chain\n",
"\n",
"This QA chain queries the Neptune graph database using SPARQL and returns a human-readable response."
]
},
{
Expand All @@ -288,7 +282,31 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"How many organizations are in the graph\"\"\")"
"from langchain_aws import ChatBedrockConverse\n",
"from langchain_aws.chains import create_neptune_sparql_qa_chain\n",
"\n",
"MODEL_ID = \"anthropic.claude-3-5-sonnet-20241022-v2:0\"\n",
"llm = ChatBedrockConverse(\n",
" model_id=MODEL_ID,\n",
" temperature=0,\n",
")\n",
"\n",
"chain = create_neptune_sparql_qa_chain(\n",
" llm=llm,\n",
" graph=graph,\n",
" examples=EXAMPLES,\n",
")\n",
"\n",
"result = chain.invoke({\"query\": \"How many organizations are in the graph?\"})\n",
"print(result[\"result\"].content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extra questions\n",
"Here are a few more prompts to try on the graph data that was ingested.\n"
]
},
{
Expand All @@ -297,7 +315,7 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"Are there any mergers or acquisitions\"\"\")"
"chain.invoke({\"query\": \"Are there any mergers or acquisitions?\"})"
]
},
{
Expand All @@ -306,7 +324,7 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"Find organizations\"\"\")"
"chain.invoke({\"query\": \"Find organizations.\"})"
]
},
{
Expand All @@ -315,7 +333,7 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"Find sites of MegaSystems or MegaFinancial\"\"\")"
"chain.invoke({\"query\": \"Find sites of MegaSystems or MegaFinancial.\"})"
]
},
{
Expand All @@ -324,7 +342,7 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"Find a member who is manager of one or more members.\"\"\")"
"chain.invoke({\"query\": \"Find a member who is a manager of one or more members.\"})"
]
},
{
Expand All @@ -333,7 +351,7 @@
"metadata": {},
"outputs": [],
"source": [
"chain.invoke(\"\"\"Find five members and who their manager is.\"\"\")"
"chain.invoke({\"query\": \"Find five members and their managers.\"})"
]
},
{
Expand All @@ -343,7 +361,9 @@
"outputs": [],
"source": [
"chain.invoke(\n",
" \"\"\"Find org units or suborganizations of The Mega Group. What are the sites of those units?\"\"\"\n",
" {\n",
" \"query\": \"Find org units or suborganizations of The Mega Group. What are the sites of those units?\"\n",
" }\n",
")"
]
}
Expand Down
21 changes: 16 additions & 5 deletions docs/docs/integrations/providers/aws.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -310,23 +310,34 @@ from langchain_community.chat_message_histories import DynamoDBChatMessageHistor

## Graphs

### Amazon Neptune

>[Amazon Neptune](https://aws.amazon.com/neptune/)
> is a high-performance graph analytics and serverless database for superior scalability and availability.
For the Cypher and SPARQL integrations below, we need to install the `langchain-aws` library.

```bash
pip install langchain-aws
```

### Amazon Neptune with Cypher

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

```python
from langchain_community.graphs import NeptuneGraph
from langchain_community.graphs import NeptuneAnalyticsGraph
from langchain_community.chains.graph_qa.neptune_cypher import NeptuneOpenCypherQAChain
from langchain_aws.graphs import NeptuneGraph
from langchain_aws.graphs import NeptuneAnalyticsGraph
from langchain_aws.chains import create_neptune_opencypher_qa_chain
```

### Amazon Neptune with SPARQL

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

```python
from langchain_community.graphs import NeptuneRdfGraph
from langchain_community.chains.graph_qa.neptune_sparql import NeptuneSparqlQAChain
from langchain_aws.graphs import NeptuneRdfGraph
from langchain_aws.chains import create_neptune_sparql_qa_chain
```


Expand Down
8 changes: 8 additions & 0 deletions docs/docs/integrations/providers/falkordb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ See a [usage example](/docs/integrations/graphs/falkordb).
```python
from langchain_community.chains.graph_qa.falkordb import FalkorDBQAChain
```

## Memory

See a [usage example](/docs/integrations/memory/falkordb_chat_message_history).

```python
from langchain_falkordb import FalkorDBChatMessageHistory
```
21 changes: 21 additions & 0 deletions docs/docs/integrations/providers/fmp-data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# FMP Data (Financial Data Prep)

> [FMP-Data](https://pypi.org/project/fmp-data/) is a python package for connecting to
> Financial Data Prep API. It simplifies how you can access production quality data.

## Installation and Setup

Get an `FMP Data` API key by
visiting [this page](https://site.financialmodelingprep.com/pricing-plans?couponCode=mehdi).
and set it as an environment variable (`FMP_API_KEY`).

Then, install [langchain-fmp-data](https://pypi.org/project/langchain-fmp-data/).

## Tools

See an [example](https://github.com/MehdiZare/langchain-fmp-data/tree/main/docs).

```python
from langchain_fmp_data import FMPDataTool, FMPDataToolkit
```
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"source": [
"### Configure\n",
"\n",
"Here we define the conncection to Elasticsearch. In this example we use a locally running instance. Alternatively, you can make an account in [Elastic Cloud](https://cloud.elastic.co/) and start a [free trial](https://www.elastic.co/cloud/cloud-trial-overview)."
"Here we define the connection to Elasticsearch. In this example we use a locally running instance. Alternatively, you can make an account in [Elastic Cloud](https://cloud.elastic.co/) and start a [free trial](https://www.elastic.co/cloud/cloud-trial-overview)."
]
},
{
Expand Down
Loading

0 comments on commit d007dc2

Please sign in to comment.