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.

Merge branch 'development' into coderabbitai/docstrings/87d041a

Christian051a70b90e3e
diff --cc src/adapters/graph.py
index 515738b,7e9c1ac..f6e72dd
--- a/src/adapters/graph.py
+++ b/src/adapters/graph.py
@@@ -384,34 -382,19 +386,32 @@@ class GraphAdapter
similarity_threshold: float = 0.0,
) -> List[Tuple[Node, List[Tuple[Predicate, Node, List[Tuple[Predicate, Node]]]]]]:
"""
- Get the 2nd degree hops for a list of nodes.
-
+ Compute second-degree neighbor hops for the given starting node UUIDs using vector-store–based filtering.
+
Parameters:
- from_uuids: List[str]: The list of node UUIDs to start from.
- flattened: bool: Whether to return simplified nodes and relationships.
- vector_store_adapter: VectorStoreClient: The vector store adapter to use.
- brain_id: str: The brain ID to use.
-
+ from_uuids: List[str] — UUIDs of the starting nodes to explore.
+ flattened: bool — When true, nodes and predicates are returned as lightweight dicts with core fields (`uuid`, `name`, `labels`/`direction`) instead of full objects.
+ vector_store_adapter: VectorStoreClient — Vector store used to fetch embeddings and perform similarity-based filtering.
+ brain_id: str — Identifier of the brain/graph space to query.
+ similarity_threshold: float — Optional threshold for additional similarity-based filtering (0.0 disables the extra check).
+
Returns:
- List[Tuple[Node, List[Tuple[Predicate, Node, List[Tuple[Predicate, Node]]]]]]: The list of 2nd degree hops.
+ List[Tuple[Node, List[Tuple[Predicate, Node, List[Tuple[Predicate, Node]]]]]] — A list where each item corresponds to a starting node and contains:
+ - the starting node (or its flattened representation),
+ - a list of first-degree entries, each being a tuple of (predicate, first-degree node, list of second-degree (predicate, node) tuples).
"""
- # TODO: add a way to light weight the output
-
def flatten_node(n):
+ """
+ Return a flattened node representation when the surrounding `flattened` flag is true, otherwise return the original node.
+
+ Parameters:
+ n: Node
+ The node to convert.
+
+ Returns:
+ dict: A dictionary with keys `uuid`, `labels`, and `name` when `flattened` is true, otherwise the original node object.
+ """
return (
{"uuid": n.uuid, "labels": n.labels, "name": n.name} if flattened else n
)
diff --cc src/core/agents/kg_agent.py
index 503ebef,62e54f4..0666bec
--- a/src/core/agents/kg_agent.py
+++ b/src/core/agents/kg_agent.py
@@@ -257,18 -237,14 +267,22 @@@ class KGAgent
return response
def retrieve_neighbors(
- self, node: Node, looking_for: Optional[Union[str, Iterable[str]]], limit: int
+ self,
+ node: Node,
+ looking_for: Optional[Union[str, Iterable[str]]],
+ limit: int,
+ brain_id: str = "default",
) -> RetrieveNeighborsOutputSchema:
"""
- Retrieve the neighbors of a node.
+ Retrieve neighboring nodes and relationship information for a given node, filtered by optional criteria and capped by a maximum result count.
+
+ Parameters:
+ node (Node): The main node whose neighbors should be retrieved.
+ looking_for (Optional[Union[str, Iterable[str]]]): A single reason string or an iterable of reason strings used to filter or prioritize which neighbors to return; if None, no extra filtering is applied.
+ limit (int): Maximum number of neighbor entries to return.
+
+ Returns:
+ RetrieveNeighborsOutputSchema: Structured neighbor data containing the matching nodes, relationships, and associated properties.
"""
graph_db_prop_keys = self.kg.get_graph_property_keys()
diff --cc src/core/agents/tools/janitor_agent/JanitorAgentSearchEntitiesTool.py
index 61b4892,d940d4f..5925390
--- a/src/core/agents/tools/janitor_agent/JanitorAgentSearchEntitiesTool.py
+++ b/src/core/agents/tools/janitor_agent/JanitorAgentSearchEntitiesTool.py
@@@ -77,24 -69,11 +77,24 @@@ class JanitorAgentSearchEntitiesTool(Ba
)
def _run(self, *args, **kwargs) -> str:
+ """
+ Search multiple query strings for matching entities in the knowledge graph and vector store, and return the aggregated results as a JSON-formatted mapping keyed by a sanitized query string.
+
+ Parameters:
+ args: If provided, the first positional argument is treated as the list of query strings to process.
+ kwargs:
+ queries (List[str]): List of query strings to search for when not passed as a positional argument.
+
+ Returns:
+ str: A JSON string mapping each sanitized query to either a list of found entity objects (each serialized to JSON) or a message indicating no matches were found.
+ """
- _query = ""
++
+ _queries = []
++
if len(args) > 0:
- _query = args[0]
+ _queries = args[0] if isinstance(args[0], list) else [args[0]]
else:
_queries = kwargs.get("queries", [])
-
- if len(_queries) == 0:
return "No queries provided in the arguments or kwargs"
found_entities: Dict[str, Union[str, List[Node]]] = {}
diff --cc src/lib/llm/client_small.py
index 5fa9c2a,5ca18aa..b220475
--- a/src/lib/llm/client_small.py
+++ b/src/lib/llm/client_small.py
@@@ -107,24 -96,8 +107,24 @@@ class LLMClientSmall(LLM)
return self._langchain_model
def generate_text(
- self, prompt: str, max_new_tokens: int = 100000, timeout: int = None
+ self, prompt: str, max_new_tokens: int = 65536, timeout: int = None
) -> str:
+ """
+ Generate plain-text completion for a prompt using the configured Vertex AI model.
+
+ If `prompt` is empty or only whitespace, returns the fixed message "Input prompt is empty". The method will retry transient failures up to 3 times and enforce the provided `timeout` per attempt.
+
+ Parameters:
+ prompt (str): The input prompt to complete.
+ max_new_tokens (int): Maximum number of tokens to generate for the completion. If falsy, no token limit is passed to the API.
+ timeout (int): Maximum seconds to wait for a single generation attempt; defaults to the client's default timeout.
+
+ Returns:
+ str: The generated plain-text completion, or "Input prompt is empty" when the prompt is empty.
+
+ Raises:
+ TimeoutError: If generation times out or all retry attempts fail.
+ """
if not prompt or len(prompt.strip()) == 0:
return "Input prompt is empty"