Polyweave

@polyweave/sampler (1.0.2)

Published 2026-07-11 00:57:21 +00:00 by Dvorak

Installation

@polyweave:registry=https://hub.kl1.tenere.ai/api/packages/Polyweave/npm/
npm install @polyweave/sampler@1.0.2
"@polyweave/sampler": "1.0.2"

About this package

Sampler

Prompt decorrelation and test-time sampling utilities for Polyweave protocols.

Synopsis

import { createSampler, createSampleVariants } from '@polyweave/sampler';

const sampler = createSampler({ words: ['alpha', 'beta', 'gamma'] });

const tag = sampler.sampleTag();
// { id: 'uuid', uuids: [...], words: ['alpha', 'gamma', 'beta'], ... }

const decorated = sampler.decoratePrompt('What is the capital of France?');
// { prompt: '[POLYWEAVE_SAMPLE uuid alpha-gamma-beta]\n...\n\nWhat is...', prefix, tag }

const variants = sampler.variants('Explain gravity', 3);
// 3 decorrelated prompt variants

Install

npm install @polyweave/sampler

Description

Sampler creates decorrelated prompt variants using random nonce tags. Each variant prepends a unique [POLYWEAVE_SAMPLE <uuid> <words>] prefix for diversity-gated sampling in LLM workflows.

API

createSampler(options)

Convenience factory returning bound sampleTag, decoratePrompt, and variants methods.

createSampleTag(options)

Generate a nonce tag with random words and UUIDs.

Parameters:

  • options.words: word list (default DEFAULT_WORDS)
  • options.wordCount: number of words to pick (default 3)
  • options.uuidCount: number of UUIDs (default 1)
  • options.random: PRNG function (default Math.random)
  • options.uuid: UUID generator (default crypto.randomUUID)

createDecorrelatedPrompt(prompt, options)

Prepend a nonce prefix and decorrelation instruction to a prompt.

createSampleVariants(prompt, count, options)

Generate count decorrelated prompt variants.

DEFAULT_WORDS

Frozen array of 30 words used for nonce generation.

Tests

npm test

Tests cover tag generation, prompt decoration, variant generation, deterministic output with injected random, and UUID injection.

Requirements

Node.js 18 or later. ESM only.

License

MIT

Dependencies

Development Dependencies

ID Version
@rigor/core *

Keywords

polyweave sampler decorrelation llm prompt nonce
Details
npm
2026-07-11 00:57:21 +00:00
8
John Dvorak
SEE LICENSE IN LICENSE
3.0 KiB
Assets (1)
Versions (4) View all
1.0.5 2026-07-11
1.0.4 2026-07-11
1.0.2 2026-07-11
1.0.0 2026-07-10