- Update mkdocs.yml navigation to use new cookbook index - Create comprehensive docs/cookbook.md index - Refactor Welcome_to_Semantica.ipynb to use Markdown cells - Enhance markdown formatting in Your_First_Knowledge_Graph.ipynb and Financial_Data_Integration.ipynb - Update custom.css and version-selector.js for better styling - Populate modules.md, concepts.md, and getting-started.md with detailed content
9.7 KiB
Modules & Architecture
Semantica is built with a modular architecture, designed to be flexible and extensible. This guide provides an overview of the key modules and their responsibilities.
🏗️ Architecture Overview
The framework is organized into several core layers, each handling specific aspects of the semantic processing pipeline.
graph TD
subgraph Ingest [Ingestion Layer]
I[Ingest Module] --> P[Parse Module]
P --> N[Normalize Module]
end
subgraph Core [Core Processing]
N --> SE[Semantic Extract]
SE --> KG[Knowledge Graph]
KG --> O[Ontology]
end
subgraph Storage [Storage Layer]
KG --> VS[Vector Store]
KG --> TS[Triple Store]
end
subgraph Output [Output & Analysis]
KG --> E[Export]
KG --> V[Visualization]
KG --> R[Reasoning]
end
style Ingest fill:#e1f5fe,stroke:#01579b
style Core fill:#e8f5e9,stroke:#1b5e20
style Storage fill:#fff3e0,stroke:#e65100
style Output fill:#f3e5f5,stroke:#4a148c
📦 Core Modules
Semantica is organized into 12 core modules. Below is a detailed breakdown of each.
1. Ingest Module
Purpose: Ingest data from various sources into a unified format.
The ingest module is the entry point for data. It handles the complexity of connecting to different data sources, from local files to web streams.
- Components:
FileIngestor: Read files (PDF, DOCX, HTML, JSON, CSV, etc.)WebIngestor: Scrape and ingest web pagesFeedIngestor: Process RSS/Atom feedsStreamIngestor: Real-time data streamingDBIngestor: Database queries and ingestionEmailIngestor: Process email messagesRepoIngestor: Git repository analysis
from semantica.ingest import FileIngestor, WebIngestor
# Ingest local files
file_ingestor = FileIngestor()
documents = file_ingestor.ingest("data/")
# Ingest web content
web_ingestor = WebIngestor()
web_docs = web_ingestor.ingest("https://example.com")
2. Parse Module
Purpose: Parse and extract content from various raw formats.
Once data is ingested, the parse module extracts the raw text and metadata. It supports a wide range of formats and includes OCR capabilities.
- Components:
DocumentParser: Main parser orchestratorPDFParser: Extract text, tables, images from PDFsDOCXParser: Parse Word documentsHTMLParser: Extract content from HTMLJSONParser: Parse structured JSON dataExcelParser: Process spreadsheetsImageParser: OCR and image analysisCodeParser: Parse source code files
from semantica.parse import DocumentParser
parser = DocumentParser()
parsed_docs = parser.parse(documents)
3. Normalize Module
Purpose: Clean and normalize text for processing.
Raw text is often noisy. The normalize module cleans, standardizes, and prepares text for semantic extraction.
- Components:
TextNormalizer: Main normalization orchestratorTextCleaner: Remove noise, fix encodingDataCleaner: Clean structured dataEntityNormalizer: Normalize entity namesDateNormalizer: Standardize date formatsNumberNormalizer: Normalize numeric valuesLanguageDetector: Detect document languageEncodingHandler: Handle character encoding
from semantica.normalize import TextNormalizer
normalizer = TextNormalizer()
normalized = normalizer.normalize(parsed_docs)
4. Semantic Extract Module
Purpose: Extract entities, relationships, and semantic information.
This is the brain of the operation. It uses LLMs and NLP techniques to understand the text and extract structured knowledge.
- Components:
NERExtractor: Named Entity RecognitionRelationExtractor: Extract relationships between entitiesSemanticAnalyzer: Deep semantic analysisSemanticNetworkExtractor: Extract semantic networks
from semantica.semantic_extract import NERExtractor, RelationExtractor
# Extract entities
extractor = NERExtractor()
entities = extractor.extract(normalized_docs)
# Extract relationships
relation_extractor = RelationExtractor()
relationships = relation_extractor.extract(normalized_docs, entities)
5. Knowledge Graph (KG) Module
Purpose: Build and manage knowledge graphs.
The kg module constructs the graph from extracted entities and relationships, handling complex tasks like resolution and analysis.
- Components:
GraphBuilder: Construct knowledge graphs from entities/relationshipsGraphAnalyzer: Analyze graph structure and propertiesGraphValidator: Validate graph quality and consistencyEntityResolver: Resolve entity conflicts and duplicatesConflictDetector: Detect conflicting informationCentralityCalculator: Calculate node importance metricsCommunityDetector: Detect communities in graphsConnectivityAnalyzer: Analyze graph connectivityTemporalQuery: Query temporal knowledge graphsDeduplicator: Remove duplicate entities/relationships
from semantica.kg import GraphBuilder, GraphAnalyzer
# Build graph
builder = GraphBuilder()
kg = builder.build(entities, relationships)
# Analyze graph
analyzer = GraphAnalyzer()
metrics = analyzer.analyze(kg)
6. Embeddings Module
Purpose: Generate vector embeddings for various data types.
Embeddings are crucial for semantic search. This module generates vectors for text, images, and graph nodes.
- Components:
EmbeddingGenerator: Main embedding orchestratorTextEmbedder: Generate text embeddingsImageEmbedder: Generate image embeddingsAudioEmbedder: Generate audio embeddingsMultimodalEmbedder: Combine multiple modalitiesEmbeddingOptimizer: Optimize embedding qualityProviderAdapters: Support for OpenAI, Cohere, etc.
from semantica.embeddings import EmbeddingGenerator
generator = EmbeddingGenerator()
embeddings = generator.generate(documents)
7. Vector Store Module
Purpose: Store and search vector embeddings.
Manages the storage and retrieval of high-dimensional vectors, supporting hybrid search strategies.
- Components:
VectorStore: Main vector store interfaceFAISSAdapter: FAISS integrationHybridSearch: Combine vector and keyword searchVectorRetriever: Retrieve relevant vectors
from semantica.vector_store import VectorStore, HybridSearch
vector_store = VectorStore()
vector_store.store(embeddings, documents, metadata)
hybrid_search = HybridSearch(vector_store)
results = hybrid_search.search(query, top_k=10)
8. Reasoning Module
Purpose: Perform logical inference and reasoning.
Goes beyond simple retrieval to infer new facts and validate existing knowledge using logical rules.
- Components:
InferenceEngine: Main inference orchestratorRuleManager: Manage inference rulesDeductiveReasoner: Deductive reasoningAbductiveReasoner: Abductive reasoningExplanationGenerator: Generate explanations for inferencesRETEEngine: RETE algorithm for rule matching
from semantica.reasoning import InferenceEngine, RuleManager
inference_engine = InferenceEngine()
rule_manager = RuleManager()
new_facts = inference_engine.forward_chain(kg, rule_manager)
9. Ontology Module
Purpose: Generate and manage ontologies.
Defines the schema and structure of your knowledge domain, ensuring consistency and enabling interoperability.
- Components:
OntologyGenerator: Generate ontologies from knowledge graphsOntologyValidator: Validate ontology structureOWLGenerator: Generate OWL format ontologiesPropertyGenerator: Generate ontology propertiesClassInferrer: Infer ontology classes
from semantica.ontology import OntologyGenerator
generator = OntologyGenerator()
ontology = generator.generate_from_graph(kg)
10. Export Module
Purpose: Export data in various formats.
Allows you to take your knowledge graph and data out of Semantica for use in other tools.
- Components:
JSONExporter: Export to JSONRDFExporter: Export to RDF/XMLCSVExporter: Export to CSVGraphExporter: Export to graph formats (GraphML, GEXF)OWLExporter: Export to OWLVectorExporter: Export vectors
from semantica.export import JSONExporter, RDFExporter
json_exporter = JSONExporter()
json_exporter.export(kg, "output.json")
11. Visualization Module
Purpose: Visualize knowledge graphs and analytics.
Provides tools to visually explore your data, making it easier to understand complex relationships.
- Components:
KGVisualizer: Visualize knowledge graphsEmbeddingVisualizer: Visualize embeddings (t-SNE, PCA, UMAP)QualityVisualizer: Visualize quality metricsAnalyticsVisualizer: Visualize graph analyticsTemporalVisualizer: Visualize temporal data
from semantica.visualization import KGVisualizer
visualizer = KGVisualizer()
visualizer.visualize(kg)
12. Pipeline Module
Purpose: Build and execute processing pipelines.
Orchestrates the entire flow, connecting modules together into robust, executable workflows.
- Components:
PipelineBuilder: Build complex pipelinesExecutionEngine: Execute pipelinesFailureHandler: Handle pipeline failuresParallelismManager: Enable parallel processingResourceScheduler: Schedule resources
from semantica.pipeline import PipelineBuilder
builder = PipelineBuilder()
pipeline = builder.add_step("ingest", FileIngestor()) \
.add_step("parse", DocumentParser()) \
.build()