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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vectorhook/client

v1.0.1

Published

Official JavaScript client for VectorHook search-as-a-service platform

Downloads

8

Readme

VectorHook JavaScript Client

The official JavaScript client for VectorHook, a modern search-as-a-service platform offering AI-powered search capabilities for applications of all sizes.

Installation

Using npm

npm install @vectorhook/client

Using yarn

yarn add @vectorhook/client

Using CDN

<script src="https://cdn.vectorhook.com/sdk/v1/vectorhook-client.min.js"></script>

Initialization

// ES Module import
import VectorHook from '@vectorhook/client';

// CommonJS require
// const VectorHook = require('@vectorhook/client');

// Initialize the client
const vectorhook = new VectorHook({
  apiKey: 'your_api_key',
  baseUrl: 'https://api.vectorhook.com', // Optional, this is the default
  timeout: 30000 // Optional, timeout in milliseconds (30 seconds by default)
});

Quick Start

Create a collection

// Define a collection schema
const schema = {
  name: 'products',
  fields: [
    { name: 'id', type: 'string' },
    { name: 'name', type: 'string' },
    { name: 'description', type: 'string' },
    { name: 'price', type: 'float' },
    { name: 'categories', type: 'string[]', facet: true },
    { name: 'in_stock', type: 'bool', facet: true }
  ],
  default_sorting_field: 'price'
};

// Create the collection
const collection = await vectorhook.collections.create(schema);

Add documents

// Add a single document
const document = {
  id: '1',
  name: 'Wireless Headphones',
  description: 'Premium noise-cancelling wireless headphones with 20-hour battery life',
  price: 199.99,
  categories: ['electronics', 'audio'],
  in_stock: true
};

const result = await vectorhook.documents.create('products', document);

// Add multiple documents
const documents = [
  {
    id: '2',
    name: 'Smart Watch',
    description: 'Fitness tracker and smartwatch with heart rate monitoring',
    price: 149.99,
    categories: ['electronics', 'wearables'],
    in_stock: true
  },
  {
    id: '3',
    name: 'Bluetooth Speaker',
    description: 'Portable bluetooth speaker with 360-degree sound',
    price: 79.99,
    categories: ['electronics', 'audio'],
    in_stock: true
  }
];

const results = await vectorhook.documents.import('products', documents);

Search documents

// Perform a basic search
const searchParams = {
  q: 'wireless headphones',
  query_by: 'name,description',
  sort_by: 'price:asc',
  per_page: 10
};

const results = await vectorhook.search.search('products', searchParams);

Track events

// Track a search event
await vectorhook.events.track({
  event_type: 'search',
  collection: 'products',
  user_id: '123', // Optional user ID
  anonymous_id: 'anon_456', // Optional anonymous user ID
  properties: {
    query: 'wireless headphones',
    filters: { price_range: '100-200', in_stock: true },
    results_count: 15,
    page: 1
  }
});

// Track a click event
await vectorhook.events.track({
  event_type: 'click',
  collection: 'products',
  document_id: '1234', // ID of the clicked document
  user_id: '123',
  anonymous_id: 'anon_456',
  properties: {
    position: 3, // Position in search results
    query: 'wireless headphones',
    source: 'search_results'
  }
});

Documentation

For complete documentation, visit https://docs.vectorhook.com.

Features

  • Collections API: Create, retrieve, and manage collections
  • Documents API: Create, retrieve, update, and delete documents
  • Search API: Perform search operations with filtering, faceting, and sorting
  • Events API: Track user interactions with search results
  • Users API: Identify and track users for personalized search experiences
  • Analytics API: Get insights into search behavior and system performance

Core Modules

Collections API

// List all collections
const collections = await vectorhook.collections.list();

// Create a collection
const collection = await vectorhook.collections.create(schema);

// Get a collection by name
const collection = await vectorhook.collections.get('products');

// Delete a collection
await vectorhook.collections.delete('products');

// Create a synonym
await vectorhook.collections.createSynonym('products', {
  symbols: ['phone', 'mobile', 'smartphone'],
  root: 'phone'
}, 'phone-synonyms');

// Create an override (curation)
await vectorhook.collections.createOverride('products', {
  rule: { query: 'headphones', match: 'exact' },
  includes: [{ id: '1234', position: 1 }]
}, 'headphones-curation');

Documents API

// Create a document
const document = await vectorhook.documents.create('products', {
  id: '1',
  name: 'Product Name',
  price: 99.99
});

// Import multiple documents
const results = await vectorhook.documents.import('products', documents);

// Get a document by ID
const document = await vectorhook.documents.get('products', '1');

// Update a document
const result = await vectorhook.documents.update('products', '1', updatedDocument);

// Delete a document
await vectorhook.documents.delete('products', '1');

Search API

// Basic search
const results = await vectorhook.search.search('products', {
  q: 'wireless',
  query_by: 'name,description'
});

// Faceted search
const results = await vectorhook.search.search('products', {
  q: 'wireless',
  query_by: 'name,description',
  facet_by: 'categories,brand,in_stock'
});

// Filtered search
const results = await vectorhook.search.search('products', {
  q: 'wireless',
  query_by: 'name,description',
  filter_by: 'price:< 200 && in_stock:true'
});

// Multi-search
const results = await vectorhook.search.multiSearch({
  searches: [
    {
      collection: 'products',
      q: 'headphones'
    },
    {
      collection: 'blog_posts',
      q: 'headphones'
    }
  ]
});

Events API

// Track an event
await vectorhook.events.track({
  event_type: 'view',
  collection: 'products',
  document_id: '123',
  user_id: 'user_456'
});

// Get all events
const events = await vectorhook.events.getEvents({
  page: 1,
  per_page: 20
});

// Get events for a collection
const events = await vectorhook.events.getCollectionEvents('products', {
  event_type: 'click'
});

// Get events for a user
const events = await vectorhook.events.getUserEvents({
  user_id: 'user_123'
});

Users API

// Identify a user
await vectorhook.users.identify({
  user_id: 'user_123',
  properties: {
    name: 'John Doe',
    email: '[email protected]'
  }
});

// Get a user profile
const profile = await vectorhook.users.getProfile('user_123', {
  include_recent_activity: 'true'
});

// Get user activity
const activity = await vectorhook.users.getActivity('user_123', {
  limit: 20,
  include_documents: 'true'
});

Analytics API

// Get analytics overview
const overview = await vectorhook.analytics.getOverview({
  start_date: 1620000000,
  end_date: 1620086400
});

// Get event timeline
const timeline = await vectorhook.analytics.getTimeline({
  event_type: 'search',
  interval: 'day'
});

// Get system health
const health = await vectorhook.analytics.getHealth();

Error Handling

try {
  const results = await vectorhook.search.search('products', {
    q: 'wireless headphones',
    query_by: 'name,description'
  });
  
  // Process results
  console.log(results);
} catch (error) {
  if (error.status === 404) {
    console.error('Collection not found:', error.message);
  } else if (error.status === 401) {
    console.error('Authentication error:', error.message);
  } else {
    console.error('API error:', error.message);
  }
}

Support

If you have any questions or need further assistance, don't hesitate to reach out to our support team at [email protected] or visit our Community Forum.

License

This project is licensed under the MIT License - see the LICENSE file for details.