Aerostack
memory

ai-extract-keywords Edge Function — Ai

AI

Extracts the top N keywords from text using TF-IDF inspired scoring with built-in English stopword filtering, no external API calls required.

navin @navin verified
Updated Mar 12, 2026
GitHub

Edge function ai-extract-keywords Extracts the top N keywords from text using TF-IDF inspired scoring with built-in English stopword filtering, no external API calls required.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.

terminal — aerostack cli
$ npx aerostack add navin/ai-extract-keywords
smart_toy

Use with AI Assistants

MCP

Connect Claude, Cursor, or any MCP-compatible client — then call this function by slug

① Add MCP Server

Add this once — access all Aerostack functions from your AI tool.

claude_desktop_config.json
{
  "mcpServers": {
    "aerostack": {
      "url": "https://mcp.aerostack.dev",
      "type": "http"
    }
  }
}

② Call this function

Ask your AI to use the call_function tool with this slug:

call_function
call_function({
  slug: "ai-extract-keywords",
  args: {
    "text": "example_text",
    "topN": 10,
    "minLength": 3,
    "includeScores": false,
    "stopwords": null
  }
})

ai-extract-keywords — Extract top keywords from text using TF-IDF scoring

Extracts the most relevant keywords from any text using TF-IDF inspired scoring with built-in English stopwords — no external API calls.


API

POST /api/ai-extract-keywords

Request body

Field Type Required Default Description
text string Text to extract keywords from
topN number 10 Maximum keywords to return
minLength number 3 Minimum word length to consider
includeScores boolean false Return {keyword, score} objects instead of plain strings
stopwords string[] English defaults Custom stopword list to override built-in list

Success response (200)

{
  "success": true,
  "data": {
    "keywords": ["machine", "learning", "neural", "network", "training"],
    "count": 5
  }
}

With includeScores: true:

{
  "success": true,
  "data": {
    "keywords": [
      { "keyword": "machine", "score": 0.0423 },
      { "keyword": "learning", "score": 0.0381 }
    ],
    "count": 2
  }
}

Error responses

Code HTTP When
INVALID_INPUT 400 Missing or empty text
INTERNAL_ERROR 500 Unexpected error

Usage

cURL
curl -X POST "$FUNCTION_URL" \
  -H "Content-Type: application/json" \
  -d '{"text": "Machine learning and AI are transforming the software industry.", "topN": 5, "includeScores": true}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ text: articleBody, topN: 10 }),
});
const { data } = await response.json();
console.log(data.keywords); // ["machine", "learning", ...]
Direct import (Node / Bun / Deno)
import { aiExtractKeywords } from '@aerostack/functions/ai-extract-keywords';

const { keywords } = aiExtractKeywords({ text: document, topN: 15, includeScores: true });

Use Cases

  • Auto-tagging blog posts or knowledge base articles for search indexing.
  • Extracting topics from user messages to route them to the correct support category.
  • Building a keyword-based content recommendation engine without a full NLP pipeline.

Notes

  • Scoring is TF-IDF inspired: words that appear frequently but less uniformly score higher.
  • Pure numbers are excluded from keyword candidates.
  • The built-in stopword list covers ~120 common English function words.
  • Pass stopwords: [] to disable all stopword filtering.

Metadata

upgrade Version 1.0.0
gavel License MIT
language Language typescript
cloud Provider aerostack

Tags

ai
deployed_code

Build and publish your own functions

Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.

More AI Functions

Browse AI Functions →

Frequently asked questions

What does the ai-extract-keywords function do? +

ai-extract-keywords is a serverless edge function for ai automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.

How do I deploy the ai-extract-keywords function? +

Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/ai-extract-keywords ``` It will be live on Cloudflare Workers in seconds.

What runtime does ai-extract-keywords use? +

ai-extract-keywords runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.

Can I customise the ai-extract-keywords function? +

Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.