npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hazeljs/kag

v2.0.13

Published

Knowledge-Augmented Generation for HazelJS — entities, facts, relations, and structured reasoning

Readme

@hazeljs/kag

Entities, facts, and relationships — with provenance you can audit.

Knowledge-Augmented Generation for HazelJS — typed knowledge graphs, time-scoped facts, contradictions, and explainable multi-hop reasoning. Use when the question is “why did X change?” over structured domain state, not “which PDF page mentions X?”

KAG does not duplicate GraphRAG internals. Import document-derived graphs via importGraph(); community detection and vector search stay in @hazeljs/rag.

npm version npm downloads License: Apache-2.0

KAG vs RAG

| | KAG | RAG | | -------- | -------------------------------------------------- | --------------------------- | | Question | What entities, facts, and relationships do I know? | What passages are relevant? | | Unit | Entity / relation / fact | Document chunk | | Strength | Multi-hop structured reasoning | Semantic similarity |

Features

  • Typed primitives — KnowledgeEntity / KnowledgeRelation / KnowledgeFact with confidence + provenance
  • Tenant-partitioned store — InMemoryKnowledgeStore (Neo4j/Postgres via KnowledgeStore ports later)
  • Entity resolution — exact / normalized / semantic / custom; no auto-merge below threshold
  • Temporal + contradictions — asOf, ranked conflicts, policy keep | rank | reject
  • Industry-pluggable planner — generic by default; opt in with COMMERCE_INDUSTRY_PROFILE (or your own)
  • Explainable answers — ask({ explain: true }) returns evidence paths (not model CoT)
  • Agent OS port — inject as AgentRuntimeConfig.kagService; DNA may declare context.kag.enabled

Installation

npm install @hazeljs/kag @hazeljs/core

Quick Start

import { KnowledgeGraph, COMMERCE_INDUSTRY_PROFILE } from '@hazeljs/kag';

const knowledge = new KnowledgeGraph({
  tenantId: 'merchant-123',
  graph: 'commerce',
  industry: COMMERCE_INDUSTRY_PROFILE, // opt-in commerce vocabulary
});

await knowledge.entity({
  id: 'merchant-123',
  type: 'merchant',
  properties: { name: 'Demo Restaurant' },
});
await knowledge.entity({
  id: 'order-456',
  type: 'order',
  properties: { total: 120 },
});
await knowledge.relate({
  from: 'merchant-123',
  to: 'order-456',
  type: 'HAS_ORDER',
});

const result = await knowledge.ask('Why was settlement lower yesterday?', {
  explain: true,
});
// { answer, evidence, sources, confidence, explanation }

Entities, Relationships, Facts

Typed primitives with optional confidence, source provenance, and validFrom / validUntil.

Entity Resolution

EntityResolver strategies: exact, normalized, semantic (when embed is provided), custom. Uncertain matches stay as candidates below mergeThreshold (default 0.9).

Temporal Knowledge, Confidence, Contradictions

  • Query with asOf or currentFacts() / changes(from, to)
  • Path confidence aggregates with min (default) or product
  • Contradictions are retained; ranked by authority → timestamp → confidence → priority
  • Policy reject throws KnowledgeConflictError

Knowledge Queries & RAG Integration

HeuristicQueryPlanner is industry-agnostic by default (generic causal/temporal/comparison intents). Opt into a domain with industry: COMMERCE_INDUSTRY_PROFILE (or your own IndustryProfile). Pass { rag: true } with an injected KnowledgeRetriever to fuse document passages.

Memory Integration

promoteObservation({ validated: true, confidence }) is explicit. No automatic promotion from @hazeljs/memory.

Agent Integration

Inject KagService as AgentRuntimeConfig.kagService. DNA may declare context.kag.enabled.

Security

Every store call requires KnowledgeScope.tenantId. Optional KnowledgeAuthorizer or createCaslKnowledgeAuthorizer(can).

Production Guide

  • Start with InMemoryKnowledgeStore; design against KnowledgeStore for Neo4j/Postgres later
  • Always set tenant scope; add authorizer for entity-level access
  • Prefer explain: true for enterprise audit trails (evidence, not model CoT)

Related

License

Apache 2.0 © HazelJS

Contributing

Contributions are welcome! See CONTRIBUTING.md for details.