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
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()
Search for documents using TF-IDF similarity.
Signature
search(query: string, options?: SearchOptions<T>): SearchResult<T>[]
Parameters
| Parameter | Type | Description |
|---|
query | string | Search query |
options.topK | number | Maximum results |
options.threshold | number | Minimum score |
options.filter | function | Metadata 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
clear()
Remove all documents.
Signature
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