Source code for tools.query_golden_goddess_v2

"""Query the 'Golden Goddess' NCM RAG store for Doctrine and Definitions.

Queries the pgvector ``golden_goddess.ncm_kernel`` store, embedding the raw
query with Gemini 3072-d (matching how the store was migrated).
"""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from tool_context import ToolContext

logger = logging.getLogger(__name__)

TOOL_NAME = "query_golden_goddess_v2"
TOOL_DESCRIPTION = (
    "The Inner Oracle. Queries the 'Golden Goddess' NCM RAG store "
    "for Doctrine, Definitions, and Parallax Context."
)
TOOL_PARAMETERS = {
    "type": "object",
    "properties": {
        "query": {
            "type": "string",
            "description": "The term, emotion, or friction-point to search.",
        },
        "n_results": {
            "type": "integer",
            "description": "Number of fragments to retrieve (default 3).",
            "default": 4,
        },
    },
    "required": ["query"],
}


[docs] async def run(query: str, n_results: int = 5, ctx: "ToolContext | None" = None) -> str: """Execute this tool and return the result. Args: query (str): Search query or input string. n_results (int): The n results value. ctx ('ToolContext | None'): Tool execution context providing access to bot internals. Returns: str: Result string. """ try: from gemini_embed_pool import openrouter_embed_batch from vector_store import AsyncPgVectorCollection col = AsyncPgVectorCollection("golden_goddess", "ncm_kernel") embs = await openrouter_embed_batch([query], dimensions=3072) if not embs or not embs[0] or not any(embs[0]): return f"The Oracle is silent on '{query}'." rows = await col.query(embs[0], n_results=n_results) output = f"--- [ORACLE: '{query}'] ---\n" docs = [r.get("document") for r in rows if r.get("document")] if not docs: return f"The Oracle is silent on '{query}'." for i, doc in enumerate(docs): output += f"\n[DOCTRINE {i + 1}]:\n{doc}\n" return output except Exception as e: return f"[ERROR] Glaive shattered: {e}"