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

@anvia/graph

v1.1.4

Published

Provider-neutral knowledge graph primitives for Anvia.

Downloads

2,393

Readme

@anvia/graph

Provider-neutral schema, extraction, retrieval-context, and tool primitives for knowledge graphs.

import { defineGraphSchema, extractGraphFacts } from "@anvia/graph";
import { z } from "zod";

const schema = defineGraphSchema({
  nodes: {
    Product: {
      description: "A product or service.",
      identity: ["id"],
      properties: z.strictObject({ id: z.string(), name: z.string() }),
    },
  },
  relationships: {},
});

const facts = await extractGraphFacts({ model, schema, chunks });

Database provisioning, persistence, and query execution belong to graph adapter packages such as @anvia/neo4j and @anvia/memgraph.

Ingestion

Managed graphs accept the same raw text document shape as vector ingestion:

import { ingestGraphText } from "@anvia/graph";

const ingestion = await ingestGraphText({
  graph,
  document: {
    id: "incident-42",
    text,
    metadata: { tenant: "acme" },
  },
  extractionModel,
  embeddingModel,
  chunking: {
    strategy: "recursive",
    maxSize: 1_000,
    overlap: 100,
    separators: ["\n\n", "\n", " "],
  },
  conflict: "error",
  orphanEntities: "delete",
  factConflicts: {
    entity: {
      properties: {
        summary: "prefer-longest",
        aliases: "union",
        confidence: "max",
      },
    },
  },
});

Extraction conflicts and stored-graph write conflicts are separate policies. factConflicts resolves disagreements between chunks before persistence; conflict controls collisions with facts already stored by the graph adapter. Extraction rejects disagreements by default. Built-in property strategies include prefer-first, prefer-last, prefer-defined, prefer-longest, union, max, and min; a custom resolver receives structured candidate and source chunk data. Conflict errors and resolved warnings include the fact type, stable key, parsed identity, property, candidate values, and source chunk IDs. Resolved disagreements are returned in warnings.

Use ingestGraphDocuments() for a batch. Both functions extract facts, embed chunks and entities, and atomically replace each source document in the managed graph. Existing graph registrations are read-only and are rejected as ingestion targets by TypeScript.

The result also exposes vectorDocuments, grouped by source document ID, so a vector store can reuse the chunk embeddings without another model call:

await vectorStore.upsert({ documents: ingestion.vectorDocuments });

Every ingestion result includes a receipt with document, entity, relationship, and vector IDs, the graph write counts, warnings, an optional caller-supplied revision, and vector-stage status. Use ingestGraphTextToStores() or ingestGraphDocumentsToStores() to write the graph followed by the vector store. If the second stage fails, GraphIngestionStageError exposes a receipt with a completed graph stage and failed vector stage for queue reconciliation.

The graph and vector writes are separate transactions. Applications that require cross-store reconciliation should persist their own ingestion status and retry the incomplete write. Advanced callers can use prepareGraphDocuments() to run chunking, extraction, and embedding without writing, then pass its graph fields to graph.replaceDocuments() and its vectorDocuments to a vector store.

Search tool

Create the same Agent tool for any graph adapter implementing GraphContextRetriever:

import { createGraphSearchTool } from "@anvia/graph";

const searchGraph = createGraphSearchTool({
  name: "search_graph",
  description: "Search connected entities and supporting evidence.",
  graph,
  model: embeddingModel,
  search: {
    type: "vector",
    seeds: ["entities"],
    topK: 8,
  },
  traversal: {
    relationships: ["AFFECTS"],
    direction: "both",
    maxDepth: 2,
    maxNodes: 40,
    maxRelationships: 80,
  },
  evidence: { type: "chunks", maxChunks: 12 },
});

The graph registration controls which evidence modes are valid. Managed graphs can hydrate stored chunks, while existing graph registrations use { type: "none" }.

Exploration

Adapters implementing GraphExplorer expose a portable, bounded view for visualization:

const overview = await graph.explore({
  mode: "overview",
  nodeTypes: ["Product"],
  includeProvenance: true,
  maxNodes: 100,
  maxRelationships: 200,
});

const neighborhood = await graph.explore({
  mode: "expand",
  nodeIds: [overview.nodes[0]!.id],
  direction: "both",
  maxDepth: 1,
});

Explorer IDs are opaque and provider-specific. They are intended for follow-up expansion within the same graph, not persistence or cross-provider migration. Adapters cap overview and expansion requests, return truncation metadata, and omit reserved Anvia properties such as stored embeddings.

When includeProvenance is true, supported adapters attach source documentIds and chunkIds to nodes and relationships.