generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Removed langchain-community from poetry * Added remaining langchain-community code * Added LangChain as a dependency
- Loading branch information
1 parent
80b79a9
commit 5444b2b
Showing
12 changed files
with
456 additions
and
401 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# flake8: noqa | ||
from langchain_core.prompts.prompt import PromptTemplate | ||
|
||
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. | ||
Schema: | ||
{schema} | ||
Note: Do not include any explanations or apologies in your responses. | ||
Do not respond to any questions that might ask anything else than for you to construct a Cypher statement. | ||
Do not include any text except the generated Cypher statement. | ||
The question is: | ||
{question}""" | ||
|
||
CYPHER_GENERATION_PROMPT = PromptTemplate( | ||
input_variables=["schema", "question"], template=CYPHER_GENERATION_TEMPLATE | ||
) | ||
|
||
CYPHER_QA_TEMPLATE = """You are an assistant that helps to form nice and human understandable answers. | ||
The information part contains the provided information that you must use to construct an answer. | ||
The provided information is authoritative, you must never doubt it or try to use your internal knowledge to correct it. | ||
Make the answer sound as a response to the question. Do not mention that you based the result on the given information. | ||
Here is an example: | ||
Question: Which managers own Neo4j stocks? | ||
Context:[manager:CTL LLC, manager:JANE STREET GROUP LLC] | ||
Helpful Answer: CTL LLC, JANE STREET GROUP LLC owns Neo4j stocks. | ||
Follow this example when generating answers. | ||
If the provided information is empty, say that you don't know the answer. | ||
Information: | ||
{context} | ||
Question: {question} | ||
Helpful Answer:""" | ||
|
||
CYPHER_QA_PROMPT = PromptTemplate( | ||
input_variables=["context", "question"], template=CYPHER_QA_TEMPLATE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import annotations | ||
|
||
from typing import List, Union | ||
|
||
from langchain_core.documents import Document | ||
from langchain_core.load.serializable import Serializable | ||
from pydantic import Field | ||
|
||
|
||
class Node(Serializable): | ||
"""Represents a node in a graph with associated properties. | ||
Attributes: | ||
id (Union[str, int]): A unique identifier for the node. | ||
type (str): The type or label of the node, default is "Node". | ||
properties (dict): Additional properties and metadata associated with the node. | ||
""" | ||
|
||
id: Union[str, int] | ||
type: str = "Node" | ||
properties: dict = Field(default_factory=dict) | ||
|
||
|
||
class Relationship(Serializable): | ||
"""Represents a directed relationship between two nodes in a graph. | ||
Attributes: | ||
source (Node): The source node of the relationship. | ||
target (Node): The target node of the relationship. | ||
type (str): The type of the relationship. | ||
properties (dict): Additional properties associated with the relationship. | ||
""" | ||
|
||
source: Node | ||
target: Node | ||
type: str | ||
properties: dict = Field(default_factory=dict) | ||
|
||
|
||
class GraphDocument(Serializable): | ||
"""Represents a graph document consisting of nodes and relationships. | ||
Attributes: | ||
nodes (List[Node]): A list of nodes in the graph. | ||
relationships (List[Relationship]): A list of relationships in the graph. | ||
source (Document): The document from which the graph information is derived. | ||
""" | ||
|
||
nodes: List[Node] | ||
relationships: List[Relationship] | ||
source: Document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from abc import abstractmethod | ||
from typing import Any, Dict, List | ||
|
||
from langchain_neo4j.graphs.graph_document import GraphDocument | ||
|
||
|
||
class GraphStore: | ||
"""Abstract class for graph operations.""" | ||
|
||
@property | ||
@abstractmethod | ||
def get_schema(self) -> str: | ||
"""Return the schema of the Graph database""" | ||
pass | ||
|
||
@property | ||
@abstractmethod | ||
def get_structured_schema(self) -> Dict[str, Any]: | ||
"""Return the schema of the Graph database""" | ||
pass | ||
|
||
@abstractmethod | ||
def query(self, query: str, params: dict = {}) -> List[Dict[str, Any]]: | ||
"""Query the graph.""" | ||
pass | ||
|
||
@abstractmethod | ||
def refresh_schema(self) -> None: | ||
"""Refresh the graph schema information.""" | ||
pass | ||
|
||
@abstractmethod | ||
def add_graph_documents( | ||
self, graph_documents: List[GraphDocument], include_source: bool = False | ||
) -> None: | ||
"""Take GraphDocument as input as uses it to construct a graph.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
|
||
|
||
class DistanceStrategy(str, Enum): | ||
"""Enumerator of the Distance strategies for calculating distances | ||
between vectors.""" | ||
|
||
EUCLIDEAN_DISTANCE = "EUCLIDEAN_DISTANCE" | ||
MAX_INNER_PRODUCT = "MAX_INNER_PRODUCT" | ||
DOT_PRODUCT = "DOT_PRODUCT" | ||
JACCARD = "JACCARD" | ||
COSINE = "COSINE" |
Oops, something went wrong.