AI Submodule
The AI submodule is used to interact with the TigerGraph CoPilot service. It allows users to register custom queries, run natural language queries, and interact with the CoPilot service.
To use the AI submodule, you must first create a TigerGraphConnection object, and verify that you have a TigerGraph CoPilot service running.
For example, to use the AI submodule, you can run the following code:
from pyTigerGraph import TigerGraphConnection
conn = TigerGraphConnection(
host="https://YOUR_DB_ADDRESS",
graphname="DigitalInfra",
username="YOUR_DB_USERNAME",
password="YOUR_DB_PASSWORD"
)
conn.getToken()
conn.ai.configureCoPilotHost(hostname="http://COPILOT_ADDRESS")
conn.ai.query("How many servers are there?")
For a more detailed and varied examples, see the demo notebooks in the (TigerGraph CoPilot GitHub repository)[https://github.com/tigergraph/CoPilot/tree/main/copilot/docs/notebooks].
configureInquiryAIHost()
configureInquiryAIHost(hostname: str)
DEPRECATED: Configure the hostname of the InquiryAI service. Not recommended to use. Use configureCoPilotHost() instead.
Parameter:
-
hostname (str)
: The hostname (and port number) of the InquiryAI serivce.
configureCoPilotHost()
configureCoPilotHost(hostname: str)
Configure the hostname of the CoPilot service. Not necessary if using TigerGraph CoPilot on TigerGraph Cloud.
Parameter:
-
hostname (str)
: The hostname (and port number) of the CoPilot serivce.
registerCustomQuery()
registerCustomQuery(query_name: str, description: str = None, docstring: str = None, param_types: dict = None)
Register a custom query with the InquiryAI service.
Parameters:
-
query_name (str)
: The name of the query being registered. Required. -
description (str)
: The high-level description of the query being registered. Only used when using TigerGraph 3.x. -
docstring (str)
: The docstring of the query being registered. Includes information about each parameter. Only used when using TigerGraph 3.x. -
param_types (Dict[str, str])
: The types of the parameters. In the format {"param_name": "param_type"} Only used when using TigerGraph 3.x.Returns:
Hash of query that was registered.
updateCustomQuery()
updateCustomQuery(query_name: str, description: str = None, docstring: str = None, param_types: dict = None)
Update a custom query with the InquiryAI service.
Parameters:
-
query_name (str)
: The name of the query being updated. Required. -
description (str)
: The high-level description of the query being updated. Only used when using TigerGraph 3.x. -
docstring (str)
: The docstring of the query being updated. Includes information about each parameter. Only used when using TigerGraph 3.x. -
param_types (Dict[str, str])
: The types of the parameters. In the format {"param_name": "param_type"} Only used when using TigerGraph 3.x.Returns:
Hash of query that was updated.
deleteCustomQuery()
deleteCustomQuery(query_name: str)
Delete a custom query with the InquiryAI service.
Parameter:
-
query_name (str)
: The name of the query being deleted.Returns:
Hash of query that was deleted.
retrieveDocs()
retrieveDocs(query: str, top_k: int = 3)
Retrieve docs from the vector store.
Parameters:
-
query (str)
: The natural language query to retrieve docs with. -
top_k (int)
: The number of docs to retrieve.Returns:
List of docs retrieved.
query()
query(query)
Query the database with natural language.
Parameter:
-
query (str)
: Natural language query to ask about the database.Returns:
JSON including the natural language response, a answered_question flag, and answer sources.
coPilotHealth()
coPilotHealth()
Check the health of the CoPilot service.
Returns:
JSON response from the CoPilot service.
initializeSupportAI()
initializeSupportAI()
Initialize the SupportAI service.
Returns:
JSON response from the SupportAI service.
createDocumentIngest()
createDocumentIngest(data_source, data_source_config, loader_config, file_format)
Create a document ingest.
Parameters:
-
data_source (str)
: The data source of the document ingest. -
data_source_config (dict)
: The configuration of the data source. -
loader_config (dict)
: The configuration of the loader. -
file_format (str)
: The file format of the document ingest.Returns:
JSON response that contains the load_job_id and data_source_id of the document ingest.
runDocumentIngest()
runDocumentIngest(load_job_id, data_source_id, data_path)
Run a document ingest.
Parameters:
-
load_job_id (str)
: The load job ID of the document ingest. -
data_source_id (str)
: The data source ID of the document ingest. -
data_path (str)
: The data path of the document ingest.Returns:
JSON response from the document ingest.
searchDocuments()
searchDocuments(query, method = "hnswoverlap", method_parameters: dict)
Search documents.
Parameters:
-
query (str)
: The query to search documents with. -
method (str)
: The method to search documents with. -
method_parameters (dict)
: The parameters of the method.Returns:
JSON response from the document search.
answerQuestion()
answerQuestion(query, method = "hnswoverlap", method_parameters: dict)
Answer a question.
Parameters:
-
query (str)
: The query to answer the question with. -
method (str)
: The method to answer the question with. -
method_parameters (dict)
: The parameters of the method.Returns:
JSON response from the question answer.