NAME
MCP::Server::KnowledgeStore::TermWeight - TermWeight vector operations using Lingua::TermWeight
VERSION
version 0.001
SYNOPSIS
use MCP::Server::KnowledgeStore::TermWeight;
my $tw = MCP::Server::KnowledgeStore::TermWeight->new;
# Compute TF for a document
my $tf = $tw->compute_tf('the quick brown fox');
# Compute IDF for a corpus
my $idf = $tw->compute_idf([qw/doc1 doc2 doc3/]);
# Compute TF-IDF for a document
my $tfidf = $tw->compute_tfidf('the quick brown fox', $idf);
# Compute cosine similarity
my $similarity = $tw->cosine_similarity($vec1, $vec2);
DESCRIPTION
This module provides vector operations for semantic search using Lingua::TermWeight. It computes TF-IDF vectors and cosine similarity for ranking search results.
All operations work on the latest revisions only - historical revisions are not considered in the corpus statistics.
NAME
MCP::Server::KnowledgeStore::TermWeight - TermWeight vector operations using Lingua::TermWeight
METHODS
compute_tf
my $tf = $tw->compute_tf($text, $normalize);
Computes term frequency vector for a document. Returns a hashref of {term = weight}>.
compute_idf
my $idf = $tw->compute_idf(\@documents);
Computes inverse document frequency for a corpus. \@documents is an arrayref of document texts. Returns a hashref of {term = weight}>.
compute_tfidf
my $tfidf = $tw->compute_tfidf($text, $idf);
Computes TF-IDF vector for a document given pre-computed IDF. Returns a hashref of {term = weight}>.
cosine_similarity
my $sim = $tw->cosine_similarity($vec1, $vec2);
Computes cosine similarity between two vectors. Returns a score between 0 and 1.
SEE ALSO
Lingua::TermWeight, MCP::Server::KnowledgeStore::Store
AUTHOR
Wesley Schwengle <waterkip@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Wesley Schwengle.
This is free software, licensed under:
The (three-clause) BSD License