Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 53 additions & 110 deletions .github/workflows/trigger-docs-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# Trigger Docs Update Workflow
# =============================================================================
#
# Sends a repository_dispatch event to the agentfront-docs repo when:
# 1. A GitHub Release is published (for stable releases)
# 2. A PR is merged to a release/* branch (for docs changes before release)
# Sends a repository_dispatch event to the agentfront-docs repo when the
# Publish Release workflow completes successfully.
#
# NOTE: This workflow uses workflow_run trigger instead of release:published
# because releases created with GITHUB_TOKEN don't trigger other workflows
# (GitHub Actions limitation to prevent infinite loops).
#
# SETUP REQUIRED:
# Create a repository secret named DOCS_SYNC_TOKEN:
Expand All @@ -17,10 +20,9 @@
name: Trigger Docs Update

on:
release:
types: [published]
pull_request:
types: [closed]
workflow_run:
workflows: ["Publish Release"]
types: [completed]

permissions:
contents: read
Expand All @@ -29,120 +31,66 @@ env:
REPO_NAME: vectoriadb

jobs:
trigger-on-release:
if: github.event_name == 'release'
trigger-docs-sync:
# Only run if publish-release succeeded
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
- name: Trigger docs sync
- name: Get release info
id: release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DOCS_SYNC_TOKEN }}
script: |
const repoName = process.env.REPO_NAME;
const tag = context.payload.release.tag_name;
const sha = context.sha;
// Get the most recent release
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1
});

if (releases.length === 0) {
core.setFailed('No releases found');
return;
}

const release = releases[0];
const tag = release.tag_name;

// Extract version minor from tag (e.g., "v2.1.0" -> "2.1")
const versionMatch = tag.match(/^v?(\d+)\.(\d+)/);
const versionMinor = versionMatch ? `${versionMatch[1]}.${versionMatch[2]}` : null;

console.log(`Triggering docs sync for ${repoName}`);
console.log(` Tag: ${tag}`);
console.log(` SHA: ${sha}`);
console.log(` Version minor: ${versionMinor}`);

try {
await github.rest.repos.createDispatchEvent({
owner: 'agentfront',
repo: 'docs',
event_type: 'sync-docs',
client_payload: {
repo: repoName,
sha: sha,
tag: tag,
version_minor: versionMinor
}
});
console.log(`Successfully triggered docs sync for ${tag}`);
} catch (error) {
console.error(`Failed to trigger docs sync: ${error.message}`);
if (error.status === 404) {
console.error('Check that DOCS_SYNC_TOKEN has access to agentfront/docs');
} else if (error.status === 401) {
console.error('Check that DOCS_SYNC_TOKEN secret is set correctly');
}
throw error;
}
// Get the commit SHA for the tag
const { data: ref } = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${tag}`
});

- name: Summary
run: |
echo "## Docs Sync Triggered (Release)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Repository:** ${{ env.REPO_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ github.event.release.tag_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **SHA:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The [agentfront-docs](https://github.com/agentfront/docs) repository will sync the documentation shortly." >> $GITHUB_STEP_SUMMARY
const sha = ref.object.sha;

trigger-on-pr-merge:
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.base.ref, 'release/')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
core.setOutput('tag', tag);
core.setOutput('sha', sha);
core.setOutput('version_minor', versionMinor);

- name: Determine diff base
id: diff_base
shell: bash
run: |
set -euo pipefail

BRANCH="${{ github.event.pull_request.base.ref }}"

# Check for .release-docs-base marker file
if [ -f ".release-docs-base" ]; then
DIFF_BASE=$(cat .release-docs-base)
echo "Using diff base from .release-docs-base: $DIFF_BASE"
else
# Fallback to branch creation point
DIFF_BASE=$(git merge-base origin/main "origin/$BRANCH" 2>/dev/null || echo "")
if [ -z "$DIFF_BASE" ]; then
DIFF_BASE="HEAD~1"
fi
echo "Using fallback diff base: $DIFF_BASE"
fi

echo "diff_base=$DIFF_BASE" >> "$GITHUB_OUTPUT"

# Extract version minor from branch (e.g., "release/2.1.x" -> "2.1")
VERSION_MINOR=$(echo "$BRANCH" | sed 's/release\/\([0-9]*\.[0-9]*\).*/\1/')
echo "version_minor=$VERSION_MINOR" >> "$GITHUB_OUTPUT"
echo "Version minor: $VERSION_MINOR"
console.log(`Release: ${tag}`);
console.log(`SHA: ${sha}`);
console.log(`Version minor: ${versionMinor}`);

- name: Trigger docs sync
uses: actions/github-script@v7
with:
github-token: ${{ secrets.DOCS_SYNC_TOKEN }}
script: |
const repoName = process.env.REPO_NAME;
const branch = '${{ github.event.pull_request.base.ref }}';
const sha = context.sha;
const diffBase = '${{ steps.diff_base.outputs.diff_base }}';
const versionMinor = '${{ steps.diff_base.outputs.version_minor }}';
const prNumber = context.payload.pull_request.number;
const prTitle = context.payload.pull_request.title;
const tag = '${{ steps.release.outputs.tag }}';
const sha = '${{ steps.release.outputs.sha }}';
const versionMinor = '${{ steps.release.outputs.version_minor }}';

console.log(`Triggering docs sync for ${repoName}`);
console.log(` Branch: ${branch}`);
console.log(` Tag: ${tag}`);
console.log(` SHA: ${sha}`);
console.log(` Diff base: ${diffBase}`);
console.log(` Version minor: ${versionMinor}`);
console.log(` PR: #${prNumber} - ${prTitle}`);

try {
await github.rest.repos.createDispatchEvent({
Expand All @@ -152,33 +100,28 @@ jobs:
client_payload: {
repo: repoName,
sha: sha,
branch: branch,
diff_base: diffBase,
version_minor: versionMinor,
pr_number: prNumber,
pr_title: prTitle
tag: tag,
version_minor: versionMinor
}
});
console.log(`Successfully triggered docs sync for PR #${prNumber}`);
console.log(`Successfully triggered docs sync for ${tag}`);
} catch (error) {
console.error(`Failed to trigger docs sync: ${error.message}`);
if (error.status === 404) {
console.error('Check that DOCS_SYNC_TOKEN has access to agentfront/docs');
} else if (error.status === 401) {
console.error('Check that DOCS_SYNC_TOKEN secret is set correctly');
}
// Don't fail the workflow for docs sync issues
console.log('Continuing despite docs sync failure');
throw error;
}

- name: Summary
run: |
echo "## Docs Sync Triggered (PR Merge)" >> $GITHUB_STEP_SUMMARY
echo "## Docs Sync Triggered" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Repository:** ${{ env.REPO_NAME }}" >> $GITHUB_STEP_SUMMARY
echo "- **Branch:** ${{ github.event.pull_request.base.ref }}" >> $GITHUB_STEP_SUMMARY
echo "- **PR:** #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
echo "- **SHA:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Diff base:** ${{ steps.diff_base.outputs.diff_base }}" >> $GITHUB_STEP_SUMMARY
echo "- **Tag:** ${{ steps.release.outputs.tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **SHA:** ${{ steps.release.outputs.sha }}" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ steps.release.outputs.version_minor }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "The [agentfront-docs](https://github.com/agentfront/docs) repository will sync the documentation shortly." >> $GITHUB_STEP_SUMMARY
88 changes: 28 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,101 +4,69 @@
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)

> A lightweight, production-ready in-memory vector database for semantic search in JavaScript/TypeScript

VectoriaDB is a fast, minimal-dependency vector database designed for in-memory semantic search. Powered by [transformers.js](https://github.com/xenova/transformers.js), it's perfect for applications that need to quickly search through documents, tools, or any text-based data using natural language queries.
> Lightweight, in-memory vector database for semantic search in JavaScript/TypeScript

## Features

- **Fast**: In-memory storage with optimized HNSW indexing for O(log n) search
- **Lightweight**: Minimal dependencies, small footprint
- **Semantic Search**: Natural language queries using state-of-the-art embeddings
- **Type-Safe**: Full TypeScript support with generics
- **Batch Operations**: Efficient bulk insert and search
- **Flexible Filtering**: Custom metadata filtering with type safety
- **Scalable**: HNSW index for 100k+ documents with sub-millisecond search
- **Persistent**: File & Redis adapters for caching across restarts
- **Smart Updates**: Incremental updates without re-embedding (instant metadata updates)
- **Production-Ready Error Handling**: Typed error classes with specific error codes
- **Fast** - HNSW indexing for O(log n) search on 100k+ documents
- **Lightweight** - Minimal dependencies, small footprint
- **Type-Safe** - Full TypeScript support with generics
- **Flexible** - Custom metadata filtering with batch operations
- **Persistent** - File & Redis adapters for caching across restarts
- **Zero-Dep Option** - TF-IDF mode for simpler deployments

## Installation

```bash
npm install vectoriadb
# or
yarn add vectoriadb
# or
pnpm add vectoriadb
```

**Requirements:**

- Node.js 18+ (for transformers.js compatibility)
- TypeScript 5.0+ (if using TypeScript)
Requires Node.js 18+.

## Quick Start

```typescript
import { VectoriaDB } from 'vectoriadb';

// Create and initialize the database
const db = new VectoriaDB();
await db.initialize();

// Add documents
await db.add('doc-1', 'How to create a user account', {
id: 'doc-1',
category: 'auth',
author: 'Alice',
});
// Add documents with metadata
await db.add('doc-1', 'How to create a user account', { category: 'auth' });
await db.add('doc-2', 'Send email notifications', { category: 'notifications' });

await db.add('doc-2', 'Send email notifications to users', {
id: 'doc-2',
category: 'notifications',
author: 'Bob',
});

// Search
// Semantic search
const results = await db.search('creating new accounts');
console.log(results[0].metadata); // { id: 'doc-1', category: 'auth', ... }
console.log(results[0].score); // 0.87
```

## Documentation

| Guide | Description |
|-------|-------------|
| [Overview](./docs/overview.md) | Installation, quick start, configuration |
| [Indexing](./docs/guides/indexing.md) | Adding and updating documents |
| [Search](./docs/guides/search.md) | Querying with filters and thresholds |
| [Persistence](./docs/guides/persistence.md) | File and Redis storage adapters |
| [HNSW](./docs/guides/hnsw.md) | Scaling to 100k+ documents |
| [TF-IDF](./docs/guides/tfidf.md) | Zero-dependency alternative |
| [Tool Discovery](./docs/guides/tool-discovery.md) | Complete tool indexing example |
| [Error Handling](./docs/reference/errors.md) | Typed error classes |

See also the [detailed API documentation](./libs/vectoriadb/README.md).
| Topic | Link |
|-------|------|
| Get Started | [Welcome](https://agentfront.dev/docs/vectoriadb/get-started/welcome) |
| Installation | [Setup Guide](https://agentfront.dev/docs/vectoriadb/get-started/installation) |
| Quickstart | [First Steps](https://agentfront.dev/docs/vectoriadb/get-started/quickstart) |
| Indexing | [Core Guide](https://agentfront.dev/docs/vectoriadb/guides/core/indexing-basics) |
| Search | [Search Guide](https://agentfront.dev/docs/vectoriadb/guides/search/basic-search) |
| Storage | [Persistence](https://agentfront.dev/docs/vectoriadb/guides/storage/overview) |
| Scaling | [HNSW Overview](https://agentfront.dev/docs/vectoriadb/guides/scaling/hnsw-overview) |
| TF-IDF | [Alternative](https://agentfront.dev/docs/vectoriadb/guides/alternatives/tfidf) |
| Production | [Deployment](https://agentfront.dev/docs/vectoriadb/deployment/production-config) |
| API Reference | [Full API](https://agentfront.dev/docs/vectoriadb/api-reference/overview) |

## Development

```bash
# Install dependencies
yarn install

# Run tests
npx nx test vectoriadb

# Build library
npx nx build vectoriadb

# Run demo
npx nx serve vectoriadb-demo
yarn install # Install dependencies
npx nx test vectoriadb # Run tests
npx nx build vectoriadb # Build library
```

## License

Apache-2.0

## Credits
---

Built with [transformers.js](https://github.com/xenova/transformers.js) by Xenova.
Loading