Source code for langchain.chains.graph_qa.arangodb
"""Question answering over a graph."""
from __future__ import annotations
import re
from typing import Any, Dict, List, Optional
from langchain.base_language import BaseLanguageModel
from langchain.callbacks.manager import CallbackManagerForChainRun
from langchain.chains.base import Chain
from langchain.chains.graph_qa.prompts import (
    AQL_FIX_PROMPT,
    AQL_GENERATION_PROMPT,
    AQL_QA_PROMPT,
)
from langchain.chains.llm import LLMChain
from langchain.graphs.arangodb_graph import ArangoGraph
from langchain.pydantic_v1 import Field
from langchain.schema import BasePromptTemplate
[docs]class ArangoGraphQAChain(Chain):
    """Chain for question-answering against a graph by generating AQL statements."""
    graph: ArangoGraph = Field(exclude=True)
    aql_generation_chain: LLMChain
    aql_fix_chain: LLMChain
    qa_chain: LLMChain
    input_key: str = "query"  #: :meta private:
    output_key: str = "result"  #: :meta private:
    # Specifies the maximum number of AQL Query Results to return
    top_k: int = 10
    # Specifies the set of AQL Query Examples that promote few-shot-learning
    aql_examples: str = ""
    # Specify whether to return the AQL Query in the output dictionary
    return_aql_query: bool = False
    # Specify whether to return the AQL JSON Result in the output dictionary
    return_aql_result: bool = False
    # Specify the maximum amount of AQL Generation attempts that should be made
    max_aql_generation_attempts: int = 3
    @property