from a1facts import KnowledgeBase

kb = KnowledgeBase(
    name="my-knowledge-base",
    ontology_config_file="ontology.yaml",
    knowledge_sources_config_file="sources.yaml",
    use_neo4j=False
)
The KnowledgeBase class is the primary interface for working with a1facts. It encapsulates the ontology, the knowledge graph, and the knowledge acquirer, providing a unified access point to all the functionalities of the framework. To get started, you need to create an instance of the KnowledgeBase class, which requires configuration files for the ontology and knowledge sources.

__init__

Initializes a new instance of the KnowledgeBase class.
from a1facts import KnowledgeBase

kb = KnowledgeBase(
    name="my-knowledge-base",
    ontology_config_file="ontology.yaml",
    knowledge_sources_config_file="sources.yaml",
    use_neo4j=False
)

Parameters

name
str
required
The name of the knowledge base.
ontology_config_file
str
required
The path to the ontology configuration file.
knowledge_sources_config_file
str
required
The path to the knowledge sources configuration file.
use_neo4j
bool
default:"False"
If True, the knowledge base will use a Neo4j backend. Otherwise, it will use an in-memory graph.
disable_exa
bool
default:"False"
If True, the knowledge base will not use Exa search for knowledge acquisition.

query

Executes a query against the knowledge graph to retrieve information.
results = kb.query("What are the main competitors of Apple?")

Parameters

query
str
required
The query to execute against the knowledge graph.

Returns

result
str
The result of the query from the knowledge graph.

ingest_knowledge

Ingests and integrates a string of new knowledge into the knowledge graph.
kb.ingest_knowledge("Apple's latest product is the Vision Pro.")

Parameters

knowledge
str
required
The knowledge to be ingested into the knowledge graph.

Returns

result
str
The result of the knowledge ingestion operation.

acquire_knowledge_for_query

Acquires new knowledge from configured sources based on a query and integrates it into the knowledge graph.
new_knowledge = kb.acquire_knowledge_for_query("Recent news about Apple's AI strategy")

Parameters

query
str
required
The query to guide the knowledge acquisition process.

Returns

result
str
The newly acquired knowledge.

get_tools

Returns a list of tools that can be used by an AI agent to interact with the knowledge base. These tools allow the agent to query for information and acquire new knowledge.
tools = kb.get_tools()
query_tool, acquire_tool = tools

Returns

tools
list
A list containing two tool functions: query_tool and acquire_tool.

query_tool

The query_tool allows an agent to retrieve precise information from the knowledge graph by translating a natural language query into a graph traversal. Parameters
query
str
required
The natural language query to execute against the knowledge graph.
Returns
result
any
The result of the query from the knowledge graph. The type of the result will depend on the query.

acquire_tool

The acquire_tool enables an agent to ingest new information into the knowledge graph from the configured knowledge sources. It takes a query, fetches relevant data, and updates the graph according to the ontology. Parameters
query
str
required
The query to send to the knowledge acquirer. This will guide the data ingestion process.
Returns
result
any
The result from the knowledge acquirer, which may include a summary of the ingested data.