Skip to content

BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.

feat(save): preferred entities on save

Christian4deef94d4313
diff --git a/.github/workflows/development.yaml b/.github/workflows/development.yaml
new file mode 100644
index 0000000..2afbb25
--- /dev/null
+++ b/.github/workflows/development.yaml
@@ -0,0 +1,15 @@
+name: development
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ build-and-release:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with: { fetch-depth: 0 }
+ - uses: actions/setup-node@v4
+ - run: "[ NOT IMPLEMENTED YET ]"
diff --git a/.github/workflows/tags.yaml b/.github/workflows/tags.yaml
new file mode 100644
index 0000000..18fa089
--- /dev/null
+++ b/.github/workflows/tags.yaml
@@ -0,0 +1,41 @@
+name: release-on-tag
+
+on:
+ push:
+ tags:
+ - "v*"
+ branches:
+ - main
+
+jobs:
+ build-and-release:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ with: { fetch-depth: 0 }
+ - name: Get tag
+ id: vars
+ run: echo "TAG=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
+
+ - uses: actions/setup-node@v4
+ with: { node-version: "20" }
+ - run: npm ci && npm run build
+
+ - uses: docker/setup-buildx-action@v3
+ - uses: docker/login-action@v3
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ - uses: docker/build-push-action@v6
+ with:
+ context: .
+ push: true
+ tags: |
+ ghcr.io/${{ github.repository }}/web:${{ steps.vars.outputs.TAG }}
+ ghcr.io/${{ github.repository }}/web:${{ github.sha }}
+
+ - uses: softprops/action-gh-release@v2
+ with:
+ tag_name: ${{ steps.vars.outputs.TAG }}
+ generate_release_notes: true
diff --git a/src/constants/prompts/kg_agent.py b/src/constants/prompts/kg_agent.py
index 67b7d5c..71e00e6 100644
--- a/src/constants/prompts/kg_agent.py
+++ b/src/constants/prompts/kg_agent.py
@@ -43,6 +43,8 @@ This is the information to update the knowledge graph:
{information}
== END OF INFORMATION ==
+{preferred_entities}
+
This are the provided parameters and information used to distinguish the nodes from each other, use this to identify, search and update nodes.
{identification_params}
diff --git a/src/core/agents/kg_agent.py b/src/core/agents/kg_agent.py
index ff4e6f6..d96796b 100644
--- a/src/core/agents/kg_agent.py
+++ b/src/core/agents/kg_agent.py
@@ -98,12 +98,19 @@ class KGAgent:
information: str,
metadata: Optional[dict],
identification_params: Optional[dict],
+ preferred_entities: Optional[list[str]],
) -> str:
"""
Update the knowledge graph with new information.
"""
self._get_agent(identification_params, metadata)
+
+ preferred_entities_prompt = f"""
+ You must prioritize the extraction of the following entities: {preferred_entities},
+ search and extract triplets including these entities first.
+ """
+
response = self.agent.invoke(
{
"messages": [
@@ -111,6 +118,9 @@ class KGAgent:
"role": "user",
"content": KG_AGENT_UPDATE_PROMPT.format(
information=information,
+ preferred_entities=(
+ preferred_entities_prompt if preferred_entities else ""
+ ),
metadata=metadata,
identification_params=identification_params,
),
diff --git a/src/workers/tasks/ingestion.py b/src/workers/tasks/ingestion.py
index fb07a96..5ae2ef1 100644
--- a/src/workers/tasks/ingestion.py
+++ b/src/workers/tasks/ingestion.py
@@ -92,6 +92,7 @@ def ingest_data(self, args: dict):
information=information,
metadata={**payload.meta_keys, "resource_id": text_chunk.id},
identification_params=payload.identification_params,
+ preferred_entities=payload.preferred_extraction_entities,
)
return self.request.id