Nasty.Interop.RagexBridge (Nasty v0.3.0)
View SourceOptional integration with Ragex knowledge graph for context-aware code generation.
This module provides utilities to query the Ragex knowledge graph for:
- Available functions in the codebase
- Function signatures and documentation
- Semantic similarity search for function suggestions
The bridge gracefully degrades if Ragex is not available or not running.
Usage
# Check if Ragex is available
if RagexBridge.available?() do
# Query for function suggestions
{:ok, functions} = RagexBridge.suggest_functions("sort a list")
endConfiguration
The bridge can be configured via application environment:
config :nasty, :ragex,
enabled: true,
path: "/path/to/ragex"
Summary
Functions
Checks if Ragex integration is available and enabled.
Enhances an intent with context from the knowledge graph.
Queries the knowledge graph for modules matching a pattern.
Gets function signature and documentation from the knowledge graph.
Suggests functions from the codebase based on natural language query.
Functions
@spec available?() :: boolean()
Checks if Ragex integration is available and enabled.
Examples
iex> RagexBridge.available?()
false # Unless Ragex is configured and running
@spec enhance_intent(Nasty.AST.Intent.t()) :: {:ok, Nasty.AST.Intent.t()} | {:error, term()}
Enhances an intent with context from the knowledge graph.
Adds suggestions for available functions that match the intent's action.
Examples
intent = %Intent{type: :action, action: "sort", target: "list"}
{:ok, enhanced} = RagexBridge.enhance_intent(intent)
# intent.metadata will include :ragex_suggestions
Queries the knowledge graph for modules matching a pattern.
Examples
{:ok, modules} = RagexBridge.find_modules("Enum")
# => ["Enum", "Enumerable"]
@spec get_function_info(String.t(), String.t(), non_neg_integer() | nil) :: {:ok, map()} | {:error, term()}
Gets function signature and documentation from the knowledge graph.
Parameters
module- Module name (e.g., "Enum")function- Function name (e.g., "sort")arity- Function arity (optional)
Returns
{:ok, %{signature: String.t(), doc: String.t(), examples: [String.t()]}}{:error, :not_found}- Function not in knowledge graph{:error, :ragex_unavailable}- If Ragex is not available
Examples
{:ok, info} = RagexBridge.get_function_info("Enum", "sort", 1)
# => %{signature: "sort(enumerable)", doc: "Sorts...", ...}
Suggests functions from the codebase based on natural language query.
Uses semantic search via Ragex's vector embeddings to find relevant functions.
Parameters
query- Natural language description of desired functionalityopts- Options::limit- Maximum number of suggestions (default: 5):threshold- Minimum similarity score 0.0-1.0 (default: 0.7):module- Filter by module name (optional)
Returns
{:ok, [%{name: String.t(), module: String.t(), doc: String.t(), score: float()}]}{:error, :ragex_unavailable}- If Ragex is not available{:error, reason}- Other errors
Examples
{:ok, suggestions} = RagexBridge.suggest_functions("sort a list")
# => [{%{name: "sort", module: "Enum", doc: "Sorts...", score: 0.95}, ...}]