npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

searchable-record-cache

1.0.2

@d_cassidy

npmHomeRepoSnykSocket
Downloads:17
$ npm install searchable-record-cache
DailyWeeklyMonthlyYearly

searchable-record-cache

A record cache with Hamming distance-based similarity search.

Installation

npm install searchable-record-cache

Usage

const { SearchableRecordCache, SearchableBucketRecordCache } = require('searchable-record-cache')

// Basic cache - scans all documents
const cache = new SearchableRecordCache({
  maxAge: 60000, // optional triggers gc, default off
  maxSize: 10000 // optional triggers gc, default off
})

cache.add(simhashKey, value)

const results = cache.search(queryHash, {
  closest: 10, // number of results
  values: 10, // values per key
  maxScan: 10000 // limit scan size
})

// Bucket cache - faster for large datasets
const bucketCache = new SearchableBucketRecordCache({
  prefixBytes: 2 // bucket by first N bytes
})

bucketCache.add(simhashKey, value)

const results = bucketCache.search(queryHash, {
  closest: 10,
  values: 10,
  prefixRadius: 2 // max Hamming distance for prefix matching
})

API

new SearchableRecordCache(opts?)

  • maxAge - max age in ms before eviction
  • maxSize - max number of entries

cache.add(key, value)

Add a value under a Buffer key (e.g., a SimHash).

cache.search(id, opts?)

Find keys closest to id by Hamming distance. Returns [{ key, distance, values }].

new SearchableBucketRecordCache(opts?)

Like SearchableRecordCache but buckets keys by prefix for faster lookups on large datasets.

  • prefixBytes - number of prefix bytes for bucketing (default: 2)

cache.destroy()

Clean up resources.

License

Apache-2.0