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

@layrx/search-indexer

v0.1.3

Published

Semantic and metadata search indexer for LayrX repository intelligence

Downloads

235

Readme

@layrx/search-indexer

Search Indexer for LayrX. Performs semantic and metadata-based retrieval over repository entities using embeddings from the Embedding Worker and metadata from the Knowledge Graph.

Architecture

User Query
     ↓
SearchIndexer (public API)
     ↓
SearchEngine (candidate loading + filtering)
     ↓
Embeddings (SQLite) + Memory (Knowledge Graph) + Files (recency)
     ↓
RankingEngine (multi-signal scoring)
     ↓
Search Results

| File | Responsibility | |------|----------------| | SearchIndexer.ts | Orchestrator and public API | | SearchEngine.ts | Candidate loading, filtering, search execution | | RankingEngine.ts | Extensible multi-factor ranking | | SimilarityCalculator.ts | Cosine similarity and text relevance helpers | | SearchFilters.ts | Zod validation and filter utilities | | SearchStatistics.ts | Query logs and aggregate metrics | | SearchTypes.ts | Shared types |

Prerequisites: Repository indexed → dependency graph → memory built → embeddings generated.

Search types

| Type | Description | |------|-------------| | semantic | Cosine similarity between query and stored embedding vectors | | exact | Exact name or path match | | prefix | Prefix/substring match on name or path | | hybrid | Weighted combination of all ranking factors (default) |

Ranking factors

Hybrid mode combines:

  • Embedding similarity (45%) — vector cosine similarity
  • Exact name match (25%) — case-insensitive name equality
  • Path relevance (15%) — path segment overlap
  • Graph relationships (10%) — relation count from memory_relations
  • Recently modified (5%) — recency from files.modified_at

Weights are configurable via SearchIndexerOptions.rankingWeights.

Filters

  • entityType — File, Function, Class, etc.
  • directory — path prefix (e.g. src/components)
  • fileExtension — e.g. .ts or ts
  • repositoryId — scope to a repository

Public API

import { indexRepository } from '@layrx/repository';
import { buildDependencyGraph } from '@layrx/dependency-graph';
import { buildMemory } from '@layrx/memory';
import { generateAll } from '@layrx/embedding-worker';
import {
  search,
  searchByType,
  searchByPath,
  getSuggestions,
  getStatistics,
} from '@layrx/search-indexer';

await indexRepository('./my-repo');
await buildDependencyGraph('./my-repo');
buildMemory('./my-repo');
await generateAll('./my-repo');

const results = await search('Button', './my-repo', 'hybrid');
console.log(results.results);

await searchByType('Button', 'Function', './my-repo');
await searchByPath('Button', 'src', './my-repo');
getSuggestions('But', './my-repo');
getStatistics('./my-repo');

Result shape

Each result includes:

  • entityId, entityType, name, path
  • score (0–1)
  • matchedReason — why the entity matched

Statistics

  • totalIndexedEntities
  • averageSearchTime
  • cacheHitRate — placeholder (0 until AI Cache Manager)
  • topSearchTypes
  • lastIndexedAt

Logging

Search started → Candidates loaded → Ranking completed → Results returned → Errors

Schema

search_index_metadata

Per-repository indexed entity counts and timestamps.

search_query_log

Query history for statistics (query, search type, duration, result count).

Search flow

User Query → Load Memory + Embeddings → Apply Filters → Embed Query (semantic/hybrid)
→ Rank Candidates → Return Top Results → Log Statistics

Future improvements

  • Approximate nearest neighbor (ANN) index for large vector sets
  • External vector database sync (pgvector, Qdrant, Pinecone)
  • Query result caching via AI Cache Manager
  • Faceted search and result highlighting
  • Cross-repository search

Tests

npm run test --workspace=@layrx/search-indexer

Do not use this package for caching, security scanning, or HTTP APIs — those belong to later features.