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

@molecule/api-semantic-search

v1.0.2

Published

Semantic search over any document corpus for molecule.dev — composes the ai-embeddings + ai-vector-store bonds (index + search)

Readme

@molecule/api-semantic-search

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

@molecule/api-semantic-search — semantic search over any document corpus.

Composes the @molecule/api-ai-embeddings and @molecule/api-ai-vector-store bonds into a reusable "index a corpus, then semantically search it" capability. Wire an embeddings provider and a vector-store provider at startup (see remarks), then:

Quick Start

import { indexDocuments, search, removeDocuments } from '@molecule/api-semantic-search'

await indexDocuments({
  collection: 'docs',
  documents: [
    { id: 'a', text: 'Cats are feline animals.', metadata: { topic: 'animals' } },
    { id: 'b', text: 'Cars are fast vehicles.', metadata: { topic: 'vehicles' } },
  ],
})

const hits = await search({
  collection: 'docs',
  query: 'domestic feline pet',
  topK: 3,
  filter: [{ field: 'topic', operator: 'eq', value: 'animals' }],
})

await removeDocuments({ collection: 'docs', ids: ['a'] })

Type

utility

Installation

npm install @molecule/api-semantic-search @molecule/api-ai-embeddings @molecule/api-ai-vector-store

API

Interfaces

IndexDocumentsParams

Parameters for {@link indexDocuments}.

interface IndexDocumentsParams {
  /** The collection/namespace to index the documents into. */
  collection: string
  /** The documents to embed and upsert. An empty array is a no-op. */
  documents: SemanticDocument[]
  /** Embedding model override (provider-specific). Falls back to the provider default. */
  model?: string
}

IndexResult

Result of {@link indexDocuments}.

interface IndexResult {
  /** Number of documents embedded and upserted. */
  indexed: number
  /** Dimensionality of the embedding vectors (0 when no documents were indexed). */
  dimension: number
}

RemoveDocumentsParams

Parameters for {@link removeDocuments}.

interface RemoveDocumentsParams {
  /** The collection/namespace to remove documents from. */
  collection: string
  /** Ids of the documents to remove. */
  ids: string[]
}

SearchHit

A single semantic-search hit.

interface SearchHit {
  /** The matched document's id. */
  id: string
  /** Similarity score (higher is more similar). */
  score: number
  /** Metadata stored with the matched document, if any. */
  metadata?: Record<string, unknown>
  /** The matched document's original text, if the store retained it. */
  content?: string
}

SearchParams

Parameters for {@link search}.

interface SearchParams {
  /** The collection/namespace to search within. */
  collection: string
  /** The natural-language query to embed and match against the corpus. */
  query: string
  /** Maximum number of results to return (provider default applies when omitted). */
  topK?: number
  /** Optional metadata filters to narrow results before scoring. */
  filter?: MetadataFilter[]
  /** Minimum similarity score threshold — hits below this are excluded. */
  minScore?: number
  /** Embedding model override (provider-specific). Falls back to the provider default. */
  model?: string
}

SemanticDocument

A single document to index into a semantic-search collection.

interface SemanticDocument {
  /** Stable unique identifier for this document (used as the vector record id). */
  id: string
  /** The document's text — embedded and stored so it can be returned on a hit. */
  text: string
  /** Arbitrary metadata stored alongside the vector and usable as a search filter. */
  metadata?: Record<string, unknown>
}

Functions

indexDocuments(params)

Embed a corpus of documents and upsert them into a vector-store collection, creating the collection on first use.

When documents is empty this short-circuits and returns without touching either provider. The embedding model is chosen via model when supplied, otherwise the provider's embedDocuments default is used. The target collection is ensured idempotently — it is only created if not already present.

function indexDocuments(params: IndexDocumentsParams): Promise<IndexResult>
  • params — The collection, documents, and optional embedding model.

Returns: The number of documents indexed and the embedding dimensionality.

removeDocuments(params)

Remove previously-indexed documents from a collection by their ids.

function removeDocuments(params: RemoveDocumentsParams): Promise<void>
  • params — The collection and the ids of the documents to remove.

Returns: A promise that resolves once the documents have been deleted.

search(params)

Semantically search an indexed collection: embed the query, then return the most similar documents ranked by similarity.

The query is embedded with model when supplied, otherwise the provider's embedQuery default. topK, filter, and minScore are forwarded to the vector store to bound, narrow, and threshold the results respectively.

function search(params: SearchParams): Promise<SearchHit[]>
  • params — The collection, query text, and optional topK/filter/minScore/model.

Returns: The matching documents (id, score, metadata, content) ranked most-similar first.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-ai-embeddings >=1.0.1
  • @molecule/api-ai-vector-store >=1.0.1

Runtime Dependencies

  • @molecule/api-ai-embeddings
  • @molecule/api-ai-vector-store

Wiring: @molecule/api-ai-embeddings and @molecule/api-ai-vector-store are provider-singleton cores — wire them with each core's setProvider(), NOT with bond() (bonding those category names is silently ignored):

import { setProvider as setEmbeddings } from '@molecule/api-ai-embeddings'
import { setProvider as setVectorStore } from '@molecule/api-ai-vector-store'
import { provider as embeddings } from '@molecule/api-ai-embeddings-openai'
import { provider as vectorStore } from '@molecule/api-ai-vector-store-memory'

setEmbeddings(embeddings)
setVectorStore(vectorStore)

Provider prereqs apply: -openai embeddings need OPENAI_API_KEY; -local embeddings download their model on first use (network + several hundred MB of runtime). The -memory vector store keeps the index in process memory — it is lost on restart and not shared across processes; use -pgvector / -pinecone / -chroma for persistence. Both providers throw a "no provider" error from the first indexDocuments/search call when unwired.