kg_chat.implementations package

Submodules

kg_chat.implementations.duckdb_implementation module

Implementation of the DatabaseInterface for DuckDB.

class kg_chat.implementations.duckdb_implementation.DuckDBImplementation(data_dir, llm_config, doc_dir_or_file=None)

Bases: DatabaseInterface

Implementation of the DatabaseInterface for DuckDB.

clear_database()

Clear the database.

create_edges(edges)

Create edges in the database.

create_nodes(nodes)

Create nodes in the database.

execute_query(query)

Execute a SQL query against the DuckDB database.

execute_query_using_langchain(prompt)

Execute a query against the database using Langchain.

execute_unsafe_operation(operation)

Execute an unsafe operation.

get_human_response(prompt)

Get a human response from the database.

get_structured_response(prompt)

Get a structured response from the database.

is_safe_command(command)

Check if a command is safe to execute.

Return type:

bool

load_kg()

Load the Knowledge Graph into the database.

show_schema()

Show the schema of the database.

toggle_safe_mode(enabled)

Toggle safe mode on or off.

kg_chat.implementations.neo4j_implementation module

Implementation of the DatabaseInterface for Neo4j.

class kg_chat.implementations.neo4j_implementation.Neo4jImplementation(data_dir, doc_dir_or_file=None, uri='bolt://localhost:7687', username='neo4j', password='password', llm_config=None)

Bases: DatabaseInterface

Implementation of the DatabaseInterface for Neo4j.

clear_database()

Clear the Neo4j database.

create_edges(edges)

Create relationships between nodes.

create_nodes(nodes)

Create nodes in the Neo4j database.

ensure_index()

Ensure that the index on :Node(id) exists.

execute_query(query)

Execute a Cypher query against the Neo4j database.

execute_query_using_langchain(query)

Execute a Cypher query against the Neo4j database using Langchain.

execute_unsafe_operation(operation, *args, **kwargs)

Execute an unsafe operation.

get_human_response(prompt)

Get a human response from the Neo4j database.

get_structured_response(prompt)

Get a structured response from the Neo4j database.

static initialize_agent(tools, llm, agent=None, callback_manager=None, agent_path=None, agent_kwargs=None, *, tags=None, **kwargs)

Load an agent executor given tools and LLM.

Parameters:
  • tools (Sequence[BaseTool]) – List of tools this agent has access to.

  • llm (BaseLanguageModel) – Language model to use as the agent.

  • agent (Optional[AgentType]) – Agent type to use. If None and agent_path is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.

  • callback_manager (Optional[BaseCallbackManager]) – CallbackManager to use. Global callback manager is used if not provided. Defaults to None.

  • agent_path (Optional[str]) – Path to serialized agent to use. If None and agent is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.

  • agent_kwargs (Optional[dict]) – Additional keyword arguments to pass to the underlying agent. Defaults to None.

  • tags (Optional[Sequence[str]]) – Tags to apply to the traced runs. Defaults to None.

  • kwargs (Any) – Additional keyword arguments passed to the agent executor.

Return type:

AgentExecutor

Returns:

An agent executor.

Raises:
  • ValueError – If both agent and agent_path are specified.

  • ValueError – If agent is not a valid agent type.

  • ValueError – If both agent and agent_path are None.

is_safe_command(command)

Check if a command is safe to execute.

Return type:

bool

load_kg(block_size=5000)

Load the Knowledge Graph into the Neo4j database.

show_schema()

Show the schema of the Neo4j database.

toggle_safe_mode(enabled)

Toggle safe mode on or off.

Module contents

Implementations of the chatbot.

class kg_chat.implementations.DuckDBImplementation(data_dir, llm_config, doc_dir_or_file=None)

Bases: DatabaseInterface

Implementation of the DatabaseInterface for DuckDB.

clear_database()

Clear the database.

create_edges(edges)

Create edges in the database.

create_nodes(nodes)

Create nodes in the database.

execute_query(query)

Execute a SQL query against the DuckDB database.

execute_query_using_langchain(prompt)

Execute a query against the database using Langchain.

execute_unsafe_operation(operation)

Execute an unsafe operation.

get_human_response(prompt)

Get a human response from the database.

get_structured_response(prompt)

Get a structured response from the database.

is_safe_command(command)

Check if a command is safe to execute.

Return type:

bool

load_kg()

Load the Knowledge Graph into the database.

show_schema()

Show the schema of the database.

toggle_safe_mode(enabled)

Toggle safe mode on or off.

class kg_chat.implementations.Neo4jImplementation(data_dir, doc_dir_or_file=None, uri='bolt://localhost:7687', username='neo4j', password='password', llm_config=None)

Bases: DatabaseInterface

Implementation of the DatabaseInterface for Neo4j.

clear_database()

Clear the Neo4j database.

create_edges(edges)

Create relationships between nodes.

create_nodes(nodes)

Create nodes in the Neo4j database.

ensure_index()

Ensure that the index on :Node(id) exists.

execute_query(query)

Execute a Cypher query against the Neo4j database.

execute_query_using_langchain(query)

Execute a Cypher query against the Neo4j database using Langchain.

execute_unsafe_operation(operation, *args, **kwargs)

Execute an unsafe operation.

get_human_response(prompt)

Get a human response from the Neo4j database.

get_structured_response(prompt)

Get a structured response from the Neo4j database.

static initialize_agent(tools, llm, agent=None, callback_manager=None, agent_path=None, agent_kwargs=None, *, tags=None, **kwargs)

Load an agent executor given tools and LLM.

Parameters:
  • tools (Sequence[BaseTool]) – List of tools this agent has access to.

  • llm (BaseLanguageModel) – Language model to use as the agent.

  • agent (Optional[AgentType]) – Agent type to use. If None and agent_path is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.

  • callback_manager (Optional[BaseCallbackManager]) – CallbackManager to use. Global callback manager is used if not provided. Defaults to None.

  • agent_path (Optional[str]) – Path to serialized agent to use. If None and agent is also None, will default to AgentType.ZERO_SHOT_REACT_DESCRIPTION. Defaults to None.

  • agent_kwargs (Optional[dict]) – Additional keyword arguments to pass to the underlying agent. Defaults to None.

  • tags (Optional[Sequence[str]]) – Tags to apply to the traced runs. Defaults to None.

  • kwargs (Any) – Additional keyword arguments passed to the agent executor.

Return type:

AgentExecutor

Returns:

An agent executor.

Raises:
  • ValueError – If both agent and agent_path are specified.

  • ValueError – If agent is not a valid agent type.

  • ValueError – If both agent and agent_path are None.

is_safe_command(command)

Check if a command is safe to execute.

Return type:

bool

load_kg(block_size=5000)

Load the Knowledge Graph into the Neo4j database.

show_schema()

Show the schema of the Neo4j database.

toggle_safe_mode(enabled)

Toggle safe mode on or off.