Semantica Framework - Use Case Examples

Use Case 1: Enterprise Knowledge Graph Construction

Scenario

A large enterprise needs to build a unified knowledge graph from diverse internal sources: company documents (PDFs, Word files), emails, databases, and web content. The knowledge graph should enable semantic search, relationship discovery, and support AI-powered assistants.

Implementation

from semantica import Semantica
from semantica.ingest import FileIngestor, EmailIngestor, DBIngestor

# Initialize framework
core = Semantica(
    graph_db="neo4j",
    merge_entities=True,
    resolve_conflicts=True
)

# Ingest from multiple sources
file_ingestor = FileIngestor(recursive=True)
sources = []
sources.extend(file_ingestor.ingest("/company/documents/"))
sources.extend(file_ingestor.ingest("/company/reports/"))

email_ingestor = EmailIngestor()
sources.extend(email_ingestor.ingest("/company/emails/"))

db_ingestor = DBIngestor(connection_string="postgresql://...")
sources.extend(db_ingestor.ingest("SELECT * FROM knowledge_base"))

# Build unified knowledge graph
kg = core.build_knowledge_graph(
    sources=sources,
    merge_entities=True,
    resolve_conflicts=True,
    generate_embeddings=True
)

# Export to Neo4j for production use
kg.to_neo4j("bolt://neo4j-server:7687", "neo4j", "password")

print(f"✅ Built knowledge graph: {kg.node_count} nodes, {kg.edge_count} edges")

Expected Outcomes

Benefits

Use Case 2: GraphRAG for Research Assistant

Scenario

A research organization wants to build an AI assistant that can answer complex questions about scientific literature by combining vector search with knowledge graph traversal for better context understanding.

Implementation

from semantica import Semantica
from semantica.qa_rag import GraphRAGEngine
from semantica.vector_store import VectorStore, PineconeAdapter

# Build knowledge base from research papers
core = Semantica(
    vector_store="pinecone",
    graph_db="neo4j",
    embedding_model="text-embedding-3-large"
)

kb = core.build_knowledge_base(
    sources=["research_papers/"],
    generate_embeddings=True,
    build_graph=True
)

# Initialize GraphRAG
vector_store = VectorStore(adapter=PineconeAdapter(
    api_key="your-key",
    index_name="research-kb"
))

graphrag = GraphRAGEngine(
    vector_store=kb.vector_store,
    knowledge_graph=kb.graph,
    embedding_model="text-embedding-3-large",
    rerank=True
)

# Query with hybrid retrieval
query = "What are the main findings about climate change impacts on agriculture?"
response = graphrag.query(
    query=query,
    top_k=5,
    expand_graph=True,
    max_hops=2
)

print(f"Answer: {response.answer}")
print(f"Confidence: {response.confidence:.2f}")
print(f"Sources: {len(response.sources)}")
for source in response.sources:
    print(f"  - {source.title} (relevance: {source.score:.2f})")

Expected Outcomes

Benefits

Use Case 3: Automatic Ontology Generation for Domain Modeling

Scenario

A healthcare organization needs to create a formal ontology for their domain knowledge to enable semantic interoperability and reasoning. Manual ontology engineering is time-consuming and error-prone.

Implementation

from semantica.ontology import (
    OntologyGenerator,
    OntologyValidator,
    RequirementsSpec
)

# Define competency questions
requirements = RequirementsSpec()
requirements.add_competency_question(
    "What medical conditions exist?",
    category="entity_identification"
)
requirements.add_competency_question(
    "What are the relationships between conditions and treatments?",
    category="relationship_modeling"
)

# Generate ontology from documents
generator = OntologyGenerator(
    llm_provider="openai",
    model="gpt-4",
    validation_mode="hybrid"
)

ontology = generator.generate_from_documents(
    sources=["medical_documents/", "clinical_notes/", "research_papers/"],
    requirements=requirements,
    quality_threshold=0.95,
    namespace="https://example.org/medical#",
    prefix="med"
)

# Validate with symbolic reasoner
validator = OntologyValidator(reasoner="hermit")
validation_report = validator.validate(ontology)

if validation_report.is_consistent:
    print(f"✅ Ontology generated: {len(ontology.classes)} classes")
    print(f"✅ Validation score: {ontology.validation_score:.2f}")
    
    # Export to OWL
    from semantica.ontology import OWLGenerator
    owl_generator = OWLGenerator()
    owl_generator.generate(ontology, "medical_ontology.ttl", format="turtle")
    print("✅ Saved to medical_ontology.ttl")
else:
    print("❌ Validation issues found")
    for issue in validation_report.issues:
        print(f"  - {issue.message}")

Expected Outcomes

Benefits

Use Case 4: AI Agent with Persistent Memory

Scenario

An AI agent needs persistent memory across conversations, understanding user preferences, and maintaining context about past interactions. The agent should be able to reason about relationships and make decisions based on structured knowledge.

Implementation

from semantica.context import (
    ContextGraphBuilder,
    AgentMemory,
    ContextRetriever
)
from semantica.vector_store import VectorStore, PineconeAdapter

# Build context graph from conversations
context_builder = ContextGraphBuilder(
    extract_entities=True,
    extract_relationships=True,
    link_external_entities=True
)

context_graph = context_builder.build_from_conversations(
    conversations=["conv_history.json"],
    link_entities=True,
    extract_intents=True
)

# Initialize agent memory
vector_store = VectorStore(adapter=PineconeAdapter(
    api_key="your-key",
    index_name="agent-memory"
))

memory = AgentMemory(
    vector_store=vector_store,
    knowledge_graph=context_graph,
    retention_policy="30_days",
    max_memory_size=10000
)

# Store context
memory.store(
    content="User prefers technical documentation over tutorials",
    metadata={"user_id": "user_123", "category": "preferences"},
    entities=["User", "Documentation", "Tutorials"],
    relationships=[("prefers", "User", "Documentation")]
)

# Retrieve relevant context
context_retriever = ContextRetriever(
    memory_store=memory,
    use_graph_expansion=True,
    max_expansion_hops=2
)

relevant_context = context_retriever.retrieve(
    query="What are the user's learning preferences?",
    max_results=5,
    min_relevance_score=0.7
)

# Use context for agent decision-making
for ctx in relevant_context:
    print(f"- {ctx.content} (score: {ctx.score:.2f})")
    if ctx.related_entities:
        print(f"  Related: {[e.name for e in ctx.related_entities]}")

Expected Outcomes

Benefits

Use Case 5: Multi-Source Data Integration with Conflict Resolution

Scenario

A financial institution needs to integrate data from multiple sources (internal databases, external APIs, news feeds) into a unified knowledge graph, handling conflicts and duplicates automatically.

Implementation

from semantica import Semantica
from semantica.conflicts import ConflictDetector, ConflictResolver
from semantica.deduplication import DuplicateDetector, EntityMerger

# Initialize with conflict resolution
core = Semantica(
    graph_db="neo4j",
    merge_entities=True,
    resolve_conflicts=True
)

# Build knowledge graph from multiple sources
kg = core.build_knowledge_graph(
    sources=[
        "internal_database/",
        "external_apis/",
        "news_feeds/"
    ],
    merge_entities=True,
    resolve_conflicts=True
)

# Detect and resolve conflicts
conflict_detector = ConflictDetector()
conflicts = conflict_detector.detect_conflicts(
    entities=kg.entities,
    properties=["revenue", "employee_count", "market_cap"]
)

print(f"⚠️  Found {len(conflicts)} conflicts")

# Resolve conflicts automatically
conflict_resolver = ConflictResolver()
for conflict in conflicts:
    resolution = conflict_resolver.resolve(
        conflict=conflict,
        strategy="highest_confidence"  # or "most_recent", "source_priority"
    )
    print(f"✅ Resolved: {conflict.entity.name}.{conflict.property} = {resolution.chosen_value}")

# Detect and merge duplicates
duplicate_detector = DuplicateDetector()
duplicates = duplicate_detector.find_duplicates(
    entities=kg.entities,
    similarity_threshold=0.85
)

entity_merger = EntityMerger()
merged = entity_merger.merge_duplicates(
    duplicates=duplicates,
    strategy="highest_confidence"
)

print(f"✅ Merged {len(duplicates)} duplicate groups into {len(merged)} canonical entities")

# Quality assessment
from semantica.kg_qa import QualityAssessor
assessor = QualityAssessor()
report = assessor.assess(kg)

print(f"✅ Quality Score: {report.overall_score}/100")
print(f"   Completeness: {report.completeness_score}/100")
print(f"   Consistency: {report.consistency_score}/100")

Expected Outcomes

Benefits

Target User Personas

Persona 1: AI/ML Engineer

Persona 2: Data Engineer

Persona 3: Knowledge Manager

Persona 4: Researcher


Document Version: 1.0 | Last Updated: 2025 | Semantica Framework Use Cases