> ## Documentation Index
> Fetch the complete documentation index at: https://docs.a1facts.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# KnowledgeBase

> The KnowledgeBase class is the main entry point for interacting with the a1facts knowledge base.

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.

<RequestExample>
  ```python theme={null}
  from a1facts import KnowledgeBase

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

### Parameters

<ParamField body="name" type="str" required>
  The name of the knowledge base.
</ParamField>

<ParamField body="ontology_config_file" type="str" required>
  The path to the ontology configuration file.
</ParamField>

<ParamField body="knowledge_sources_config_file" type="str" required>
  The path to the knowledge sources configuration file.
</ParamField>

<ParamField body="use_neo4j" type="bool" default="False">
  If `True`, the knowledge base will use a Neo4j backend. Otherwise, it will use an in-memory graph.
</ParamField>

<ParamField body="disable_exa" type="bool" default="False">
  If `True`, the knowledge base will not use Exa search for knowledge acquisition.
</ParamField>

***

## `query`

Executes a query against the knowledge graph to retrieve information.

<RequestExample>
  ```python theme={null}
  results = kb.query("What are the main competitors of Apple?")
  ```
</RequestExample>

### Parameters

<ParamField body="query" type="str" required>
  The query to execute against the knowledge graph.
</ParamField>

### Returns

<ResponseField name="result" type="str">
  The result of the query from the knowledge graph.
</ResponseField>

***

## `ingest_knowledge`

Ingests and integrates a string of new knowledge into the knowledge graph.

<RequestExample>
  ```python theme={null}
  kb.ingest_knowledge("Apple's latest product is the Vision Pro.")
  ```
</RequestExample>

### Parameters

<ParamField body="knowledge" type="str" required>
  The knowledge to be ingested into the knowledge graph.
</ParamField>

### Returns

<ResponseField name="result" type="str">
  The result of the knowledge ingestion operation.
</ResponseField>

***

## `acquire_knowledge_for_query`

Acquires new knowledge from configured sources based on a query and integrates it into the knowledge graph.

<RequestExample>
  ```python theme={null}
  new_knowledge = kb.acquire_knowledge_for_query("Recent news about Apple's AI strategy")
  ```
</RequestExample>

### Parameters

<ParamField body="query" type="str" required>
  The query to guide the knowledge acquisition process.
</ParamField>

### Returns

<ResponseField name="result" type="str">
  The newly acquired knowledge.
</ResponseField>

***

## `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.

<RequestExample>
  ```python theme={null}
  tools = kb.get_tools()
  query_tool, acquire_tool = tools
  ```
</RequestExample>

### Returns

<ResponseField name="tools" type="list">
  A list containing two tool functions: `query_tool` and `acquire_tool`.
</ResponseField>

***

### `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**

<ParamField body="query" type="str" required>
  The natural language query to execute against the knowledge graph.
</ParamField>

**Returns**

<ResponseField name="result" type="any">
  The result of the query from the knowledge graph. The type of the result will depend on the query.
</ResponseField>

***

### `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**

<ParamField body="query" type="str" required>
  The query to send to the knowledge acquirer. This will guide the data ingestion process.
</ParamField>

**Returns**

<ResponseField name="result" type="any">
  The result from the knowledge acquirer, which may include a summary of the ingested data.
</ResponseField>
