Skip to content

Commit

Permalink
Add entrypoints, move around docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Oct 1, 2023
1 parent 718f523 commit af64e3c
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import GraphDBExample from "@examples/chains/graph_db_neo4j.ts";
import GraphDBReturnDirectExample from "@examples/chains/graph_db_return_direct.ts";
import GraphDBCustomPromptExample from "@examples/chains/graph_db_custom_prompt.ts";

# Neo4j Cypher graph QA

This example uses Neo4j database, which is a native graph database.

## Set up
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
label: 'Graph databases'
position: 1
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
This walkthrough uses Neo4j to demonstrate the graph database integrations
# Neo4j

## Setup

Install the dependencies needed for Neo4j:

```bash npm2yarn
npm install neo4j-driver
```

## Usage

This walkthrough uses Neo4j to demonstrate a graph database integration.

### Instantiate a graph and retrieve information the the graph by generating Cypher query language statements using GraphCypherQAChain.

import CodeBlock from "@theme/CodeBlock";
import GraphDBExample from "@examples/chains/graph_db_neo4j.ts";

<CodeBlock language="typescript">{GraphDBExample}</CodeBlock>
6 changes: 3 additions & 3 deletions examples/src/chains/graph_db_custom_prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Neo4jGraph } from "langchain/graphs/neo4j_graph.js";
import { OpenAI } from "langchain/llms/openai.js";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher.js";
import { Neo4jGraph } from "langchain/graphs/neo4j_graph";
import { OpenAI } from "langchain/llms/openai";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher";
import { PromptTemplate } from "langchain/prompts";

/**
Expand Down
6 changes: 3 additions & 3 deletions examples/src/chains/graph_db_neo4j.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Neo4jGraph } from "langchain/graphs/neo4j_graph.js";
import { OpenAI } from "langchain/llms/openai.js";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher.js";
import { Neo4jGraph } from "langchain/graphs/neo4j_graph";
import { OpenAI } from "langchain/llms/openai";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher";

/**
* This example uses Neo4j database, which is native graph database.
Expand Down
6 changes: 3 additions & 3 deletions examples/src/chains/graph_db_return_direct.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Neo4jGraph } from "langchain/graphs/neo4j_graph.js";
import { OpenAI } from "langchain/llms/openai.js";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher.js";
import { Neo4jGraph } from "langchain/graphs/neo4j_graph";
import { OpenAI } from "langchain/llms/openai";
import { GraphCypherQAChain } from "langchain/chains/graph_qa/cypher";

/**
* This example uses Neo4j database, which is native graph database.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import type {
VectorizeIndex,
Fetcher,
Expand Down
6 changes: 6 additions & 0 deletions langchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ chains/query_constructor/ir.d.ts
chains/sql_db.cjs
chains/sql_db.js
chains/sql_db.d.ts
chains/graph_qa/cypher.cjs
chains/graph_qa/cypher.js
chains/graph_qa/cypher.d.ts
embeddings/base.cjs
embeddings/base.js
embeddings/base.d.ts
Expand Down Expand Up @@ -589,6 +592,9 @@ storage/in_memory.d.ts
storage/ioredis.cjs
storage/ioredis.js
storage/ioredis.d.ts
graphs/neo4j_graph.cjs
graphs/neo4j_graph.js
graphs/neo4j_graph.d.ts
hub.cjs
hub.js
hub.d.ts
Expand Down
16 changes: 16 additions & 0 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
"chains/sql_db.cjs",
"chains/sql_db.js",
"chains/sql_db.d.ts",
"chains/graph_qa/cypher.cjs",
"chains/graph_qa/cypher.js",
"chains/graph_qa/cypher.d.ts",
"embeddings/base.cjs",
"embeddings/base.js",
"embeddings/base.d.ts",
Expand Down Expand Up @@ -601,6 +604,9 @@
"storage/ioredis.cjs",
"storage/ioredis.js",
"storage/ioredis.d.ts",
"graphs/neo4j_graph.cjs",
"graphs/neo4j_graph.js",
"graphs/neo4j_graph.d.ts",
"hub.cjs",
"hub.js",
"hub.d.ts",
Expand Down Expand Up @@ -1266,6 +1272,11 @@
"import": "./chains/sql_db.js",
"require": "./chains/sql_db.cjs"
},
"./chains/graph_qa/cypher": {
"types": "./chains/graph_qa/cypher.d.ts",
"import": "./chains/graph_qa/cypher.js",
"require": "./chains/graph_qa/cypher.cjs"
},
"./embeddings/base": {
"types": "./embeddings/base.d.ts",
"import": "./embeddings/base.js",
Expand Down Expand Up @@ -2151,6 +2162,11 @@
"import": "./storage/ioredis.js",
"require": "./storage/ioredis.cjs"
},
"./graphs/neo4j_graph": {
"types": "./graphs/neo4j_graph.d.ts",
"import": "./graphs/neo4j_graph.js",
"require": "./graphs/neo4j_graph.cjs"
},
"./hub": {
"types": "./hub.d.ts",
"import": "./hub.js",
Expand Down
4 changes: 4 additions & 0 deletions langchain/scripts/create-entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const entrypoints = {
"chains/query_constructor": "chains/query_constructor/index",
"chains/query_constructor/ir": "chains/query_constructor/ir",
"chains/sql_db": "chains/sql_db/index",
"chains/graph_qa/cypher": "chains/graph_qa/cypher",
// embeddings
"embeddings/base": "embeddings/base",
"embeddings/cache_backed": "embeddings/cache_backed",
Expand Down Expand Up @@ -235,6 +236,7 @@ const entrypoints = {
// storage
"storage/in_memory": "storage/in_memory",
"storage/ioredis": "storage/ioredis",
"graphs/neo4j_graph": "graphs/neo4j_graph",
// hub
hub: "hub",
// utilities
Expand Down Expand Up @@ -282,6 +284,7 @@ const requiresOptionalDependency = [
"callbacks/handlers/llmonitor",
"chains/load",
"chains/sql_db",
"chains/graph_qa/cypher",
"embeddings/cloudflare_workersai",
"embeddings/cohere",
"embeddings/googlevertexai",
Expand Down Expand Up @@ -401,6 +404,7 @@ const requiresOptionalDependency = [
"stores/message/planetscale",
"stores/message/xata",
"storage/ioredis",
"graphs/neo4j_graph",
// Prevent export due to circular dependency with "load" entrypoint
"hub",
"experimental/multimodal_embeddings/googlevertexai",
Expand Down
6 changes: 3 additions & 3 deletions langchain/src/chains/graph_qa/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PromptTemplate } from "../../prompts/prompt.js";

const CYPHER_GENERATION_TEMPLATE = `Task:Generate Cypher statement to query a graph database.
const CYPHER_GENERATION_TEMPLATE = `Task:Generate Cypher statement to query a graph database.
Instructions:
Use only the provided relationship types and properties in the schema.
Do not use any other relationship types or properties that are not provided.
Expand All @@ -12,7 +12,7 @@ Do not include any text except the generated Cypher statement.
The question is:
{question}`;
export const CYPHER_GENERATION_PROMPT = new PromptTemplate({
export const CYPHER_GENERATION_PROMPT = /* #__PURE__ */ new PromptTemplate({
template: CYPHER_GENERATION_TEMPLATE,
inputVariables: ["schema", "question"],
});
Expand All @@ -27,7 +27,7 @@ Information:
Question: {question}
Helpful Answer:`;
export const CYPHER_QA_PROMPT = new PromptTemplate({
export const CYPHER_QA_PROMPT = /* #__PURE__ */ new PromptTemplate({
template: CYPHER_QA_TEMPLATE,
inputVariables: ["context", "question"],
});
2 changes: 2 additions & 0 deletions langchain/src/load/import_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const optionalImportEntrypoints = [
"langchain/chains/query_constructor",
"langchain/chains/query_constructor/ir",
"langchain/chains/sql_db",
"langchain/chains/graph_qa/cypher",
"langchain/embeddings/cloudflare_workersai",
"langchain/embeddings/cohere",
"langchain/embeddings/tensorflow",
Expand Down Expand Up @@ -131,6 +132,7 @@ export const optionalImportEntrypoints = [
"langchain/stores/message/planetscale",
"langchain/stores/message/xata",
"langchain/storage/ioredis",
"langchain/graphs/neo4j_graph",
"langchain/hub",
"langchain/experimental/multimodal_embeddings/googlevertexai",
"langchain/experimental/chat_models/anthropic_functions",
Expand Down
6 changes: 6 additions & 0 deletions langchain/src/load/import_type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface OptionalImportMap {
"langchain/chains/sql_db"?:
| typeof import("../chains/sql_db/index.js")
| Promise<typeof import("../chains/sql_db/index.js")>;
"langchain/chains/graph_qa/cypher"?:
| typeof import("../chains/graph_qa/cypher.js")
| Promise<typeof import("../chains/graph_qa/cypher.js")>;
"langchain/embeddings/cloudflare_workersai"?:
| typeof import("../embeddings/cloudflare_workersai.js")
| Promise<typeof import("../embeddings/cloudflare_workersai.js")>;
Expand Down Expand Up @@ -391,6 +394,9 @@ export interface OptionalImportMap {
"langchain/storage/ioredis"?:
| typeof import("../storage/ioredis.js")
| Promise<typeof import("../storage/ioredis.js")>;
"langchain/graphs/neo4j_graph"?:
| typeof import("../graphs/neo4j_graph.js")
| Promise<typeof import("../graphs/neo4j_graph.js")>;
"langchain/hub"?:
| typeof import("../hub.js")
| Promise<typeof import("../hub.js")>;
Expand Down
2 changes: 2 additions & 0 deletions langchain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"src/chains/query_constructor/index.ts",
"src/chains/query_constructor/ir.ts",
"src/chains/sql_db/index.ts",
"src/chains/graph_qa/cypher.ts",
"src/embeddings/base.ts",
"src/embeddings/cache_backed.ts",
"src/embeddings/cloudflare_workersai.ts",
Expand Down Expand Up @@ -229,6 +230,7 @@
"src/stores/message/xata.ts",
"src/storage/in_memory.ts",
"src/storage/ioredis.ts",
"src/graphs/neo4j_graph.ts",
"src/hub.ts",
"src/util/math.ts",
"src/experimental/autogpt/index.ts",
Expand Down

0 comments on commit af64e3c

Please sign in to comment.