Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt

Use this file to discover all available pages before exploring further.

Methods available on the TFIDFVectoria class.

addDocument()

Add a document to the index.

Signature

addDocument(id: string, text: string, metadata: T): void

Example

db.addDocument('tool1', 'User authentication tool', {
  id: 'tool1',
  toolName: 'auth',
  category: 'security',
});
After adding documents, you must call reindex() before searching.

reindex()

Rebuild the TF-IDF index. Required after document changes.

Signature

reindex(): void

Example

db.addDocument('doc1', 'Text one', metadata1);
db.addDocument('doc2', 'Text two', metadata2);

// MUST reindex before searching
db.reindex();

// Now search works
const results = db.search('query');

Search for documents using TF-IDF similarity.

Signature

search(query: string, options?: SearchOptions<T>): SearchResult<T>[]

Parameters

ParameterTypeDescription
querystringSearch query
options.topKnumberMaximum results
options.thresholdnumberMinimum score
options.filterfunctionMetadata filter

Example

const results = db.search('authentication', {
  topK: 5,
  threshold: 0.1,
  filter: (m) => m.category === 'security',
});

removeDocument()

Remove a document from the index.

Signature

removeDocument(id: string): boolean

Example

const removed = db.removeDocument('tool1');
db.reindex(); // Reindex after removal

getDocument()

Get a document by ID.

Signature

getDocument(id: string): { id: string; text: string; metadata: T } | undefined

hasDocument()

Check if a document exists.

Signature

hasDocument(id: string): boolean

size()

Get the number of documents.

Signature

size(): number

clear()

Remove all documents.

Signature

clear(): void

Complete Example

import { TFIDFVectoria } from 'vectoriadb';

interface Tool {
  id: string;
  name: string;
  category: string;
}

const toolSearch = new TFIDFVectoria<Tool>();

// Add documents
toolSearch.addDocument('user-create', 'Create new user account registration signup', {
  id: 'user-create',
  name: 'createUser',
  category: 'users',
});

toolSearch.addDocument('user-delete', 'Delete remove user account termination', {
  id: 'user-delete',
  name: 'deleteUser',
  category: 'users',
});

// Reindex
toolSearch.reindex();

// Search
const results = toolSearch.search('create account');
// Returns: user-create with high score

TFIDFVectoria Constructor

Create instance

TF-IDF Guide

Usage guide