A comprehensive system for managing ontologies with multi-tenant support, RESTful API, FastMCP integration, and intelligent navigation capabilities
Project description
Ragatanga Ontology Management System
A comprehensive system for managing ontologies with multi-tenant support, RESTful API, FastMCP integration, and intelligent navigation capabilities.
Features
- Multi-tenant Architecture: Isolate ontologies across different tenants
- Ontology Management: Upload, query, delete, and modify ontologies
- RESTful API: Complete API with OpenAPI documentation
- SPARQL Query Support: Execute complex queries against ontologies
- Pheromone-based Navigation: Intelligent ontology exploration with reinforced learning paths
- MCP Agent Integration: Conversational agents powered by Model Context Protocol
- Redis Integration: Upstash Redis for persistence and caching
- File Format Support: Turtle (.ttl) as default format with support for various RDF formats
- GraphDB Integration: Connect to existing semantic databases
Installation
As a Package (Recommended)
Ragatanga is available as a package on GitHub Packages. See INSTALL.md for detailed instructions on how to configure pip and install the package.
# Quick installation (after configuring pip for GitHub Packages)
pip install ragatanga
From Source
-
Clone the repository:
git clone https://github.com/jquant/ragatanga-mcp.git cd ragatanga-mcp -
Install dependencies:
pip install -r requirements.txt -
Create a
.envfile:cp .env.example .env -
Edit the
.envfile with your configuration
Usage
As a Python Package
from ragatanga.shared.ontology_service import OntologyManager
# Initialize the ontology manager
ontology_manager = OntologyManager(tenant_id="my_tenant")
# Query an ontology
results = ontology_manager.execute_sparql(
ontology_id="my_ontology",
query="SELECT ?s ?p ?o WHERE { ?s ?p ?o . } LIMIT 10"
)
# Process results
for result in results:
print(result)
Running the Agent
from ragatanga.agent import run_agent
# Configure the agent
config = {
"tenant_id": "my_tenant",
"model": "gpt-4o"
}
# Run the agent
run_agent(config)
Or directly from the command line:
python agent.py --model gpt-4o
System Architecture
Ragatanga consists of several integrated components:
- Ontology Service: Core service for managing and querying ontologies
- Storage Services: Persistence layer for ontologies and metadata
- Ant Colony Services: Pheromone-based intelligent navigation
- Auth Services: Authentication and tenant management
- MCP Integration: Fast Model Context Protocol integration for AI agents
Running the API
Using Python directly:
python app.py
Using uvicorn directly:
uvicorn shared.ontology_service.api:app --reload
Using uv (fast Python package installer):
# Install uv
pip install uv
# Create and activate environment
uv venv
source .venv/bin/activate # On Unix/Mac
# OR
.venv\Scripts\activate # On Windows
# Install dependencies
uv pip install -r requirements.txt
# Run the application
uv run python app.py
API Endpoints
Tenant Management
GET /tenants/- List all available tenantsPOST /tenants/- Create a new tenantGET /tenants/{tenant_id}/ontologies- List all ontologies for a tenant
Ontology Management
POST /tenants/{tenant_id}/ontologies/- Upload a new ontology file (supports various formats, stored as .ttl)DELETE /tenants/{tenant_id}/ontologies/{ontology_id}- Delete an ontologyGET /tenants/{tenant_id}/ontologies/{ontology_id}/stats- Get ontology statisticsPOST /tenants/{tenant_id}/ontologies/{ontology_id}/query- Execute SPARQL queries
MCP Capabilities
The integrated Model Context Protocol (MCP) server provides the following capabilities:
Ontology Management Tools
query_ontology- Get information about a specific URIsearch_ontology- Search for entities in the ontologyexecute_sparql- Run SPARQL queries against the ontologyget_class_props- Get properties of a specific classget_class_instances- Get instances of a specific classget_subgraph- Get a visual representation of the ontology
Intelligent Navigation
explore_with_pheromones- Navigate the ontology using ant colony optimizationreinforce_knowledge_path- Strengthen successful navigation pathsanalyze_knowledge_trails- Examine emergent knowledge pathwaysvisualize_knowledge_network- Generate a Mermaid diagram of the knowledge graph
Natural Language Tools
find_concept_uri- Map natural language terms to formal ontology URIsexplore_concept- Explore a concept described in natural languagereinforce_concept_path- Reinforce paths between natural language concepts
Ontology Modification
create_class- Add a new class to the ontologycreate_property- Add a new property to the ontologycreate_individual- Add a new individual instanceupdate_entity_property- Modify properties of an entityremove_entity- Remove an entity from the ontology
Using the API
Swagger UI
API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Environment Variables
HOST- Server host (default: 0.0.0.0)PORT- Server port (default: 8000)DEBUG- Enable debug mode (default: False)UPSTASH_REDIS_REST_URL- Upstash Redis URLUPSTASH_REDIS_REST_TOKEN- Upstash Redis tokenRAGATANGA_ONTOLOGY_PATH- Path to ontology files (default: ontologies/default)ONTOLOGY_FORMAT- Ontology serialization format (default: turtle)ENABLE_LLM_COMPLETIONS- Enable LLM-powered entity completion (default: false)OPENAI_API_KEY- OpenAI API key (if LLM completions enabled)OPENAI_MODEL- OpenAI model to use (default: gpt-4o)
Context Propagation in WebSocket Tools
The server uses a context propagation mechanism to ensure that tools invoked through WebSocket connections have access to the shared application state. When a tool is called via a WebSocket, the following happens:
- The
server_lifespancontext manager initializes services (graph service, session service) and adds them to the service registry. - This shared state is yielded from the lifespan and automatically added to the Starlette app's scope.
- When handling WebSocket tool calls in
handle_tools_call():- The shared state is retrieved from
websocket.scope.get('state') - The session context for the current connection is stored in a global variable (
_SESSION_CONTEXT_{connection_id}) - The service registry is stored in a global variable (
_SERVICE_REGISTRY) - Tools can access these globals through enhanced getter functions in
server_tools.py
- The shared state is retrieved from
This approach ensures that tools invoked through WebSocket connections have access to:
- The current SessionContext (tenant/ontology ID, etc.)
- The service registry (graph service, session service, etc.)
- Any other shared state needed by tools
If you implement new tools, you can use the existing get_session_context() and get_registry() helper functions which will automatically find the correct context information.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ragatanga-0.9.0.tar.gz.
File metadata
- Download URL: ragatanga-0.9.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46dc4aaa747f6406b7ad0aa0860e854feb8685a52d94987acef80ee74c274f20
|
|
| MD5 |
a123fb117de2577d7935e803608184d4
|
|
| BLAKE2b-256 |
bcf23f165fd06e1b7ada4fb10756edc76a09b3417e75cbe1718ac0a3547e1ff3
|
File details
Details for the file ragatanga-0.9.0-py3-none-any.whl.
File metadata
- Download URL: ragatanga-0.9.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f30fe1526ac556d47016ff19a3f34e2994d391acca955b34c6b145becc07a0c
|
|
| MD5 |
80b16f0e099b6fc081145f96c30924e1
|
|
| BLAKE2b-256 |
17e4166ec92809fd4c7631876ea8bd78c98f663a18d4348b0b44b36c9ecf22ce
|