@godspeedai/cognate-cognitive-api

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3907

Dependency-free CognitiveIndex contract, retrieval pipeline, indexing projection, and conformance kit (spec §14–16).

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start: recall
  3. Keeping an index fed: the indexer projection
  4. Conformance kit for index implementations
  5. Limitations
  6. Related packages
  7. License

@godspeedai/cognate-cognitive-api

The retrieval contract for Cognate applications: a CognitiveIndex interface, the standard recall pipeline, an event-driven indexing projection, and a conformance kit for index implementations. It defines no vector database and no embedding model — implementations and embedders plug in.

When to use this package: you are building or consuming semantic recall ("find me documents like this query") and want one interface that works over any index backend, with tenant/scope filtering and authorization built into the pipeline rather than bolted on. Pick an implementation such as @godspeedai/cognate-cognitive-memory, @godspeedai/cognate-cognitive-ruvector, or @godspeedai/cognate-cognitive-rvf.

Installation

bun add @godspeedai/cognate-cognitive-api

Requires Bun >= 1.4.0. The SDK ships Bun-native TypeScript source, so add @types/bun and @types/node as dev dependencies when typechecking your project.

Quick start: recall

import { createRecall } from "@godspeedai/cognate-cognitive-api";
import { createMemoryIndex, hashingEmbedder } from "@godspeedai/cognate-cognitive-memory";

const recall = createRecall({
  index: createMemoryIndex({ dimension: 256 }),
  embedder: hashingEmbedder(256),
  resolver: {
    // Fetch authoritative content for an entry's source, with your own authorization.
    async resolve(sourceRef, actor, tenant) {
      return { kind: "ok", value: { text: "Refunds are approved by a manager." } };
    },
  },
});

const result = await recall.recall({
  text: "who approves refunds?",
  actor: { id: "alice", kind: "user" },
  tenant: "tenant-a",
  scopeIds: [],
  k: 5,
});

if (result.status === "ok") {
  for (const item of result.items) console.log(item.sourceRef, item.score);
} else {
  // "degraded": the index or embedder was unavailable; continue without cognition
  console.warn(result.reason);
}

The pipeline: embed the query, ask the index for candidates (with tenant/scope pre-filtering), re-check each candidate's provenance against the query's tenant and scopes, then fetch authoritative content through your SourceResolver. Sources that come back denied or missing are dropped silently — recall never discloses that a result existed. Results never exceed k. If the index or embedder throws, recall degrades to { status: "degraded", items: [] } unless the query sets required: true, in which case it throws CognitionUnavailableError.

Keeping an index fed: the indexer projection

cognitiveIndexer is a projection that turns durable events into index entries. You provide a deterministic extract function per event; the projection embeds the extracted documents and upserts them (idempotent by entry id, so replay is safe). When an event's payload is erased, its derived entries are removed — even across restarts.

import { cognitiveIndexer } from "@godspeedai/cognate-cognitive-api";

const indexer = cognitiveIndexer({
  name: "my-cognition",
  version: "1",
  index,               // a CognitiveIndex
  embedder,            // an Embedder
  extract: (event) =>
    event.eventType === "doc.created"
      ? [{ id: `doc:${event.eventId}`, sourceType: "event", sourceRef: `event:${event.eventId}`,
           tenant: event.tenant, scopeId: event.scopeId, semanticRef: null, eventRef: event.eventId,
           traceRef: null, metadata: {}, relationships: [], validFrom: event.occurredAt, validTo: null,
           text: String((event.payload as { title?: string }).title ?? "") }]
      : [],
});

Run it with a projection runner (the reference runtime accepts it via its projections option), or drive it yourself with @godspeedai/cognate-projections.

Conformance kit for index implementations

The @godspeedai/cognate-cognitive-api/conformance subpath exports cognitiveIndexConformance(name, make) — the behavior suite (nearest-first ordering, idempotent upserts, provenance preservation, tenant isolation, scope restriction, dimension checks) and an entry() fixture helper. Every index implementation in the Cognate family passes it unchanged; run it against your own implementation before trusting one.

Limitations

  • This package ships no index and no embedder — quality depends entirely on your choices.
  • Index candidates are never authoritative; only what your SourceResolver returns is.
  • Recall drops denied or missing sources without signaling which ones, by design.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-cognitive-api 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-cognitive-api 的常见问题

@godspeedai/cognate-cognitive-api 是什么?

Dependency-free CognitiveIndex contract, retrieval pipeline, indexing projection, and conformance kit (spec §14–16).

如何安装 @godspeedai/cognate-cognitive-api?

在项目目录运行 npm install @godspeedai/cognate-cognitive-api,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-cognitive-api 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-cognitive-api 是否存在。

@godspeedai/cognate-cognitive-api 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@godspeedai/cognate-cognitive-api 可以商用吗?

@godspeedai/cognate-cognitive-api 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-cognitive-api 的下载量有多少?

根据 npm 官方下载统计,@godspeedai/cognate-cognitive-api 在 2026/10/17 – 2026/11/15 这 30 天内被下载 3,907 次,日均约 130 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@godspeedai/cognate-cognitive-api 还在维护吗?

最新版本 0.10.0 发布于 2026/11/16(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/10/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。