Singularity / doc /AGDB /4_AGDB_enhanced_queries.md
SlappAI's picture
order
c8aa036

Core Commands and Syntax Structure

The following commands encapsulate essential functionality:

  1. Graph Creation and Initialization

    • create-graph — Initializes a new graph in AGN or AGDB format.
    • Example: create-graph -name "financial_time_series" -type "AGDB"
  2. Node and Relationship Management

    • create-node — Adds a new node to the graph.
    • create-relationship — Creates a relationship between two nodes.
    • Example: create-node -id "node_001" -type "TimeSeriesNode" -attributes {...}
    • Example: create-relationship -from "node_001" -to "node_002" -type "next"
  3. Setting Edges, Attributes, and Domains

    • set-edge — Defines an edge with specific properties (e.g., weight, type).
    • set-attribute — Sets attributes for a given node.
    • set-domain — Assigns a domain to a node or graph (e.g., "trading data").
    • Example: set-edge -from "node_001" -to "node_002" -weight 0.8
    • Example: set-attribute -node "node_001" -attributes {...}
    • Example: set-domain -graph "financial_time_series" -name "Trading"
  4. Retrieving Nodes, Relationships, and Domains

    • get-node — Retrieves node details (e.g., attributes, domain).
    • get-relationship — Retrieves relationships for a node or between nodes.
    • get-domain — Retrieves the domain context of a node.
    • Example: get-node.attribute -name "node_001"
    • Example: get-relationship -node "node_001"
    • Example: get-domain -node "node_001"
  5. AGN/AGDB Specific Commands

    • get-AGN — Retrieves relational inference policies.
    • set-AGN — Updates relational inference policies.
    • Example: get-AGN -policy "trading_inference"
    • Example: set-AGN -policy "trading_inference" -rules {...}

Proposed AGT JSON Structure

To support this query system, we can create an AGT JSON file structure that defines the graph’s metadata, nodes, attributes, relationships, and policies. This will be our template for any graph created under this system, and it will integrate AGNs, AGDBs, or both. Here’s an example of how this JSON might look:

{
    "metadata": {
        "title": "Financial Time Series AGDB",
        "source": "Sample Data Source",
        "description": "Structured AGDB with AGN policies for financial time-series data.",
        "timezone": "UTC"
    },
    "domains": {
        "TradingData": {
            "description": "Domain for trading time-series data",
            "nodes": ["TimeSeriesNode", "FeatureNode"],
            "relationships": ["temporal_sequence", "influences"]
        }
    },
    "nodes": [
        {
            "node_id": "node_001",
            "type": "TimeSeriesNode",
            "domain": "TradingData",
            "attributes": {
                "timestamp": "2024-11-04T10:45:00Z",
                "open": 1.12,
                "close": 1.15,
                "high": 1.17,
                "low": 1.10,
                "volume": 50000
            },
            "relationships": {
                "next": "node_002",
                "previous": "node_000",
                "related_features": ["open", "close"]
            }
        },
        ...
    ],
    "relationships": [
        {
            "source": "node_001",
            "target": "node_002",
            "type": "temporal_sequence",
            "attributes": {
                "weight": 0.8,
                "policy": "inferred_temporal"
            }
        }
    ],
    "policies": {
        "inference": {
            "trading_inference": {
                "rules": {
                    "time_series_trend": {
                        "relationship": "temporal_sequence",
                        "weight_threshold": 0.5
                    },
                    "volatility_correlation": {
                        "attributes": ["high", "low"],
                        "relationship": "correlates_with",
                        "weight_threshold": 0.3
                    }
                }
            }
        }
    }
}

Integration with agn_service

The agn_service module should be updated to support these new commands. Here’s how we can modify it to enable this unified query syntax:

  1. Command Parsing: Implement a command parser that can interpret commands like create-node, get-node, and set-domain. This parser would deconstruct the command and call the appropriate functions in agn_service.

  2. Unified Command Interface: Build a central function in agn_service to handle each core command, redirecting to sub-functions (e.g., get_node_info, set_attribute) based on the command and parameters passed.

  3. Function Examples for AGN and AGDB Commands

Here’s an example of how the get-node command might be handled in agn_service.

# agn_service.py

def get_node(command_params):
    node_id = command_params.get("node_id")
    attribute = command_params.get("attribute", None)
    domain = command_params.get("domain", None)

    node = query_node(node_id)
    if not node:
        return {"error": "Node not found"}

    if attribute:
        return {"attribute_value": node.attributes.get(attribute)}
    
    if domain:
        return {"domain": node.domain}
    
    return {"node_data": node.to_dict()}

Example Command Implementations

  • Command to Get Node Attribute:

    # Command: get-node.attribute -name node_001
    get_node({"node_id": "node_001", "attribute": "open"})
    

    Output:

    {"attribute_value": 1.12}
    
  • Command to Set Domain:

    # Command: set-domain -graph "financial_time_series" -name "Trading"
    set_domain("financial_time_series", "Trading")
    
  • Command to Create Relationship:

    # Command: create-relationship -from "node_001" -to "node_002" -type "next"
    create_relationship("node_001", "node_002", "next")
    

Benefits of This Approach

  1. Scalability: This unified approach supports AGNs and AGDBs equally, enabling a single system to handle relational and time-series data with minimal code duplication.

  2. Consistency: The noun-verb syntax aligns with familiar command-line paradigms like PowerShell, making it intuitive and reducing learning curves for users.

  3. Extensibility: New commands and attributes can be easily added to support additional graph types or specialized data structures without overhauling the system.

  4. Efficiency: This model is efficient for both small, simple datasets and large, complex data structures. Relationships can be predefined for known connections and inferred on-demand for larger datasets, balancing storage and computational load.


Next Steps

  1. Implement the Command Parser: Set up a parser in agn_service to handle and route each command type.
  2. Expand agn_service Functions: Build out functions in agn_service to support all primary commands (create-node, get-node, etc.).
  3. Define Standard JSON Templates: Develop JSON templates for AGDB and AGN that can be reused or adjusted for specific use cases.
  4. Testing: Test the unified command set on various data structures to ensure flexibility and efficiency across use cases.