29 Commits
Author SHA1 Message Date
pravit-ampandPravit Ampapathini 0775b0114e test(provenance): assert stored records in KG provenance suites (#946) (#1132)
* fix(provenance): use timezone-aware UTC and assert stored records (#946)

Replace datetime.utcnow() in ProvenanceManager, ProvenanceEntry,
BridgeAxiom, and GraphBuilderWithProvenance with
datetime.now(timezone.utc), matching PipelineWithProvenance.

KG workflow and integration tests now read provenance back through
get_provenance() and assert algorithm metadata instead of generated
IDs, and call tracker methods that actually persist records.

* fix(provenance): compare provenance timestamps as instants, not strings

query_recorded_between() and audit_log() filtered and sorted on raw ISO
strings. With the timezone-aware change, a store can hold both pre-existing
naive stamps and offset-bearing ones, and the two are not string-comparable:
"...500000+00:00" sorts above "...500000", so a record at the identical
instant as a naive bound falls outside the range that should contain it.

Both now parse through _parse_timestamp() before comparing, reading naive
values as UTC. This mirrors ProvenanceTracker._parse_dt() in kg/, the class
ProvenanceManager replaces, so both sides of the migration answer a range
query the same way. Unparseable stored timestamps are skipped and logged
rather than silently dropped; unparseable bounds raise ValueError.

---------

Co-authored-by: Pravit Ampapathini <pravit.amp@gmail.com>
2026-08-27 15:40:38 +05:00
cxzg007and江俊杰 14091d21fb fix(kg): compute real relationship duration for temporal stability metric (#1143)
analyze_evolution() previously appended a constant placeholder (durations.append(1)) for every bounded relationship, so the stability metric was always 1.0 when any bounded relationship existed and 0 otherwise, never reflecting actual valid-time durations.

Stability now computes the mean valid-time duration in seconds ((valid_until - valid_from).total_seconds()) across relationships with both bounds set; unbounded/half-open intervals are skipped and non-positive intervals clamped to 0. Adds unit tests and a CHANGELOG entry.

Co-authored-by: 江俊杰 <jiangjunjie.37@jd.com>
2026-08-22 14:24:47 +05:00
Mohd Kaif 6390652303 Merge branch 'main' into fix/kg-validator-entity-id 2026-08-21 19:33:26 +05:30
Guofang.Tang a3074ec454 fix(kg): keep relationship endpoint aliases in sync (#1115)
* fix(kg): keep relationship endpoint aliases in sync

* fix(kg): repair stale endpoint aliases

* test(kg): cover stale endpoint aliases

---------
2026-08-21 13:35:43 +05:00
T1mn e5c5cf0efa fix(kg): harden validator alias handling 2026-08-19 23:19:04 +08:00
T1mn 4d3259df31 fix(kg): validate entity_id aliases 2026-08-19 20:15:20 +08:00
Guofang.Tang b77e3e8c3c fix(kg): preserve entity_id aliases during entity merging (#1086)
* fix(kg): preserve entity_id aliases during merge

* fix(kg): unify entity ID extraction semantics
2026-08-19 16:17:51 +05:00
Guofang.Tang 17d878cbf3 fix(kg): honor exact entity resolution (#1026)
* fix(kg): honor exact entity resolution

* fix(kg): preserve entities without identifiers

* fix(kg): ignore blank exact entity names

---------
2026-08-18 18:03:20 +05:00
Guofang.Tang 8177d88753 fix(kg): preserve isolated nodes in graph analytics (#1011)
* fix(kg): preserve isolated nodes in graph analytics

* fix(kg): support node fallbacks and community payloads

---------
2026-08-16 11:23:24 +05:00
Guofang.Tang b8175ea801 fix(kg): make k-shortest path search side-effect free (#1000)
* fix(kg): make k-shortest path search side-effect free

* fix(kg): respect traversal direction for edge exclusion
2026-08-15 15:34:26 +05:00
Guofang.Tang 94d0c3dc07 fix(kg): remap relationship endpoints after entity resolution (#978)
* fix(kg): remap relationship endpoints after entity resolution

* fix(kg): harden relationship endpoint remapping
2026-08-14 15:37:56 +05:00
Shubham Srivastava 1ee3f2f214 fix(kg): align GraphBuilder raw-text extraction defaults with the documented contract (#941)
* fix(kg): align GraphBuilder raw-text extraction defaults with the documented contract

_extract_from_text() defaulted ner_method, relation_method and
triplet_method to "llm" and ran relation extraction unconditionally,
contradicting the build() docstring ("ml"/"pattern"/False) and the
standalone extractor defaults. Any raw-text build() therefore required a
provider, an API key, and network access without saying so.

Defaults are now ml/pattern/pattern with extract_relations=False. LLM
extraction is unchanged and now opt-in via explicit kwargs.

Also documents relation_method and extract_triplets, which the docstring
never listed, and drops the stale "Default to LLM methods as per
requirement" comment.

Closes #930

* perf(kg): reuse extractors across texts instead of rebuilding per source

Addresses review feedback on #941. NERExtractor.__init__ loads its spaCy
model eagerly when the method includes "ml", so switching the default
from "llm" to "ml" made _extract_from_text() reload the model once per
source in a multi-document build.

Extractors are now cached per (kind, method) on the builder. Adds tests
asserting single construction across repeated texts, that distinct
methods still get distinct extractors, and that the default path runs
end to end without any provider call.

* fix(kg): keep fallback method lists working with the extractor cache

The extractor cache keyed directly on `method`, but all three extractors
accept a list for fallback ordering (e.g. ner_method=["pattern", "ml"]),
so a list argument raised TypeError: unhashable type: 'list' before
extraction started. Lists are now converted to tuples for the cache key
only; the extractor still receives the original value.

Also seeds _extraction_stats in __init__. It was previously created only
in build(), so calling _extract_from_text() directly — as the report's
repro does — raised an AttributeError that the broad except swallowed and
logged as "Entity extraction failed".

Adds coverage for list methods on all three extractors, cache reuse for
equal lists, and distinct entries for different orderings.

* fix(kg): forward extracted relations into triplet extraction

_extract_from_text() passed only entities= to extract_triplets(), so
TripletExtractor re-derived relations itself whenever relations is None,
using a method taken from triplet_method rather than relation_method.
That duplicated work and could yield triplets inconsistent with the
relations already extracted.

relations is now initialized to None, holds the extracted list when
extract_relations=True succeeds, and is forwarded to extract_triplets().
When extraction is disabled or fails, None is passed and
TripletExtractor's existing self-derivation is unchanged.

Folded in at maintainer request rather than tracked as #944.

* docs(changelog): note that #878 documented the LLM defaults before this landed

#878 merged while this was in review and resolved the same code/docstring
mismatch in the opposite direction. Records that #930's decision makes
the code the side that changes, and that #878's docstring formatting is
retained.
2026-08-12 23:37:09 +05:30
KaifAhmad1andClaude Sonnet 4.6 523b02083f feat(explorer): add bidirectional path finding with directed=false param (#469)
- PathFinder.bfs_shortest_path() and dijkstra_shortest_path() gain a
  directed: bool = True parameter. When False, a temporary undirected
  view (graph.to_undirected()) is used for traversal only; the original
  directed edges are preserved and returned in the response.
- _make_undirected_view() helper added to PathFinder; falls back safely
  for non-NetworkX graph types.
- GET /api/graph/node/{id}/path exposes ?directed=false query param.
- PathResponse gains a directed: bool field echoing the mode used.
- Route now returns 404 on empty path (previously returned 200 with
  path: []).
- 21 new tests: 12 unit (TestBidirectionalPathFinding) + 9 API-level
  (TestBidirectionalPathRoute). All 120 tests pass.
- CHANGELOG updated under [Unreleased].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 15:20:12 +05:30
KaifAhmad1andClaude Sonnet 4.6 0f0800f109 feat(#402): Temporal GraphRAG Integration — TemporalGraphRetriever & TemporalQueryRewriter
- Add TemporalGraphRetriever to context_retriever.py (no new file per project convention)
  - Drop-in wrapper for ContextRetriever; filters related_entities/related_relationships
    via reconstruct_at_time(); at_time=None is a true passthrough
  - Returns new RetrievedContext objects (no in-place mutation)
  - Graceful ImportError if temporal modules unavailable

- Add at_time + header_template to ContextRetriever._generate_reasoned_response()
  and query_with_reasoning()
  - Temporal header prepended to LLM context block only when at_time is set
  - Naive datetimes normalised to UTC before formatting
  - Header built with str.replace (not .format) to prevent format-string injection

- Add TemporalQueryRewriter + TemporalQueryResult to semantica/kg/
  - Regex-only (default) and LLM-assisted extraction modes
  - Resolves temporal phrases via TemporalNormalizer (deterministic, zero LLM)
  - Word-boundary guards on intent keywords; year fallback for noun-phrase dates
  - Never calls reconstruct_at_time — extraction only

- Export TemporalGraphRetriever from semantica.context
- Export TemporalQueryRewriter, TemporalQueryResult from semantica.kg

- Add 99 tests across two new test files
  - tests/context/test_temporal_retriever.py (56 tests)
  - tests/kg/test_temporal_query_rewriter.py (43 tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 14:20:38 +05:30
KaifAhmad1 8de7cc1b6d Fix temporal reasoning review issues 2026-03-23 19:43:12 +05:30
KaifAhmad1 c6dc9d87aa Add deterministic temporal reasoning engine 2026-03-23 19:12:18 +05:30
KaifAhmad1 b2b823a5c3 Fix temporal query review follow-ups 2026-03-23 17:13:02 +05:30
KaifAhmad1 3c863e860e Implement temporal point-in-time correctness (#397) 2026-03-23 16:39:49 +05:30
KaifAhmad1 8be16f782e Fix temporal revision integrity follow-ups 2026-03-23 16:12:29 +05:30
KaifAhmad1 9faa5661f8 Core temporal data model overhaul (#396) 2026-03-23 15:53:13 +05:30
KaifAhmad1andClaude Sonnet 4.6 194a72d0f9 fix: resolve all failing tests for 0.3.0-alpha and Unreleased features
- context: fix entity extraction gating, add expand_context/_get_decision_query,
  fix _retrieve_from_vector content extraction, fix _extract_entities_from_query
- kg: add alpha/max_iter aliases and structured return to calculate_pagerank,
  fix community_detector to handle NetworkX graphs and edge tuples,
  add 9 domain tracking methods to kg_provenance, create provenance_tracker module
- pipeline: fix retry loop in execution_engine, add handle_failure+RecoveryAction
  to failure_handler, fix add_step to return step object, add validate alias and
  fix error message in pipeline_validator
- vector_store: relax batch performance threshold from 100ms to 500ms
- tests: fix Unicode encoding (emoji->ASCII), fix assertion scoping, fix
  collaboration loop scope, fix duplicate kwarg

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-06 02:54:09 +05:30
KaifAhmad1 6fc69aef2e [FEATURE] Enhanced Graph Algorithms in KG Module #292
This commit introduces comprehensive enhancements to the Knowledge Graph (KG) module with:

Major Enhancements:
- Complete algorithm suite with 30+ graph algorithms
- Unified provenance tracking system for all operations
- Comprehensive documentation and test coverage
- Enterprise-grade functionality

New Algorithm Components:
- NodeEmbedder: Node2Vec, DeepWalk, Word2Vec algorithms
- SimilarityCalculator: Cosine, Euclidean, Manhattan, Correlation metrics
- PathFinder: Dijkstra, A*, BFS, K-shortest paths
- LinkPredictor: Preferential attachment, Jaccard, Adamic-Adar
- CentralityCalculator: Degree, Betweenness, Closeness, PageRank
- CommunityDetector: Louvain, Leiden, Label propagation
- ConnectivityAnalyzer: Components, bridges, density analysis

Provenance System:
- GraphBuilderWithProvenance: Graph construction with tracking
- AlgorithmTrackerWithProvenance: Algorithm execution tracking
- Execution IDs and metadata tracking for reproducibility

Test Coverage:
- 5 comprehensive test suites with 40+ test methods
- End-to-end testing for all algorithms
- Real-world scenario testing
- Provenance integration testing

Documentation:
- Updated all module documentation with algorithm listings
- Enhanced KG reference documentation
- Comprehensive usage examples and API documentation

Technical Improvements:
- Unified provenance system integration
- Enhanced error handling and recovery
- Performance optimizations
- NetworkX compatibility with fallback implementations

Resolves: #292
Parent: Context Graphs feature
2026-02-10 21:49:11 +05:30
KaifAhmad1 9f77dfb761 Fix GraphBuilder external relationships; refs #208 #206 2026-01-18 22:10:02 +05:30
KaifAhmad1 58707ff721 fix(kg): resolve 'unhashable type: Entity' in GraphAnalyzer #159
- Robust ID extraction in CentralityCalculator, CommunityDetector, and ConnectivityAnalyzer
- Support for direct Entity objects and dictionaries as node identifiers
- Improved Entity hashability in utils/types.py
- Added integration test to verify fix and prevent regression
2026-01-08 17:23:31 +05:30
KaifAhmad1 e3b53998c3 Fix dependency issues, align GraphRAG notebook, and update changelog 2026-01-07 19:00:30 +05:30
KaifAhmad1 dcd6f25f87 docs: fix KnowledgeGraph mismatch and update tests for issue #144 2026-01-07 15:01:47 +05:30
KaifAhmad1 96702923de Remove QA components (OntologyValidator, ConflictDetector, etc) and fix residual references 2025-12-16 17:25:15 +05:30
KaifAhmad1 5d5928badf feat: enhance kg module with tests, conflict resolution placeholders, and doc updates 2025-12-11 15:21:39 +05:30
KaifAhmad1 926c518bd7 feat: comprehensive testing and fixes for Core, KG, Conflicts, and Pipeline modules 2025-12-10 15:26:05 +05:30