本页还没有译文
本页 42 段还没译成日本語,下面显示的是英文原文。Falkordb integration
还没翻译译自英文(docs.langchain.com)本页 42 段都还没译
FalkorDB LangChain JS/TS integration
The @falkordb/langchain-ts package enables developers to use FalkorDB's ultra-fast graph database alongside their LangChain applications. What this means in practice is that your application can now take natural language questions, automatically generate the corresponding Cypher queries, pull the relevant context from your graph database, and return responses in plain language. The entire translation layer gets handled for you.
The package fits into existing LangChain workflows, so if you are already using that framework for other AI capabilities, this becomes another tool in your stack. FalkorDB's low latency characteristics combine with LangChain's language model integration to provide quick responses.
About FalkorDB
An ultra-fast, multi-tenant graph database powering Generative AI, Agent Memory, Cloud Security, and Fraud Detection. FalkorDB is the first queryable Property Graph Database to leverage sparse matrices for representing the adjacency matrix in graphs and linear algebra for querying.
Installation
npm install @falkordb/langchain-ts falkordbYou'll also need LangChain and a language model:
npm install langchain @langchain/openaiQuick start
1. Start FalkorDB
The easiest way to run FalkorDB is with Docker:
docker run -p 6379:6379 -it --rm falkordb/falkordb:latest2. Basic usage
Warning
The @langchain/community package is no longer maintained. Examples that import from @langchain/community may be outdated or broken. Use with caution.
import { FalkorDBGraph } from "@falkordb/langchain-ts";
import { ChatOpenAI } from "@langchain/openai";
import { GraphCypherQAChain } from "@langchain/community/chains/graph_qa/cypher";
// Initialize FalkorDB connection
const graph = await FalkorDBGraph.initialize({
host: "localhost",
port: 6379,
graph: "movies" // Your graph name
});
// Set up the language model
const model = new ChatOpenAI({ temperature: 0 });
// Create and populate the graph with some data
await graph.query(
"CREATE (a:Actor {name:'Bruce Willis'})" +
"-[:ACTED_IN]->(:Movie {title: 'Pulp Fiction'})"
);
// Refresh the graph schema
await graph.refreshSchema();
// Create a graph QA chain
const chain = GraphCypherQAChain.fromLLM({
llm: model,
graph: graph as any, // Type assertion for LangChain compatibility
});
// Ask questions about your graph
const response = await chain.run("Who played in Pulp Fiction?");
console.log(response);
// Output: Bruce Willis played in Pulp Fiction.
// Clean up
await graph.close();API reference
FalkorDBGraph
initialize(config: FalkorDBGraphConfig): Promise<FalkorDBGraph>
Creates and initializes a new FalkorDB connection.
Config Options:
host(string, optional): Database host. Default:"localhost"port(number, optional): Database port. Default:6379graph(string, optional): Graph name to useurl(string, optional): Alternative connection URL formatenhancedSchema(boolean, optional): Enable enhanced schema details. Default:false
Example:
const graph = await FalkorDBGraph.initialize({
host: "localhost",
port: 6379,
graph: "myGraph",
enhancedSchema: true
});query(query: string): Promise<any>
Executes a Cypher query on the graph.
const result = await graph.query(
"MATCH (n:Person) RETURN n.name LIMIT 10"
);refreshSchema(): Promise<void>
Updates the graph schema information.
await graph.refreshSchema();
console.log(graph.getSchema());getSchema(): string
Returns the current graph schema as a formatted string.
getStructuredSchema(): StructuredSchema
Returns the structured schema object containing node properties, relationship properties, and relationships.
close(): Promise<void>
Closes the database connection.
await graph.close();Advanced usage
Custom cypher queries
const graph = await FalkorDBGraph.initialize({
host: "localhost",
port: 6379,
graph: "movies"
});
// Complex query
const result = await graph.query(`
MATCH (a:Actor)-[:ACTED_IN]->(m:Movie)
WHERE m.year > 2000
RETURN a.name, m.title, m.year
ORDER BY m.year DESC
LIMIT 10
`);
console.log(result.data);Multiple queries
await graph.executeQueries([
"CREATE (p:Person {name: 'Alice'})",
"CREATE (p:Person {name: 'Bob'})",
"MATCH (a:Person {name: 'Alice'}), (b:Person {name: 'Bob'}) CREATE (a)-[:KNOWS]->(b)"
]);Working with schema
await graph.refreshSchema();
// Get formatted schema
const schema = graph.getSchema();
console.log(schema);
// Get structured schema
const structuredSchema = graph.getStructuredSchema();
console.log(structuredSchema.nodeProps);
console.log(structuredSchema.relationships);Requirements
- Node.js 18 or later
- FalkorDB server running (Redis-compatible)
- LangChain 0.1.0 or later
Examples
For more examples, see the @falkordb/langchain-ts repository on GitHub.
License
MIT
Support
- GitHub Issues
- Website: https://www.falkordb.com/