Skip to content

polite-crawler 0.1.3

Choose a tag to compare

@github-actions github-actions released this 18 Oct 04:25
ce15721
  • The recipes only add to the API. Code that compiled against 0.1.1 or 0.1.2 compiles against this version, and compat.test.ts and compat-012.test.ts stay green. The capture log, the bodies and the capture ids do not change.

    • RuntimeOptions, and thus OpenOptions, has the optional recipes. OpenedCrawler, HybridCrawler and PoliteCrawler do not change.
    • polite-crawler/hours has the new compareHours and HoursComparison. Its size for a browser stays in its budget.
    • In this version, createRuntime registers the extractors before it opens a file of the store. Thus an extractor that it refuses leaves no open file.
  • The recipe SDK. defineRecipe({ name, fetch, extract }) declares what a recipe fetches and how it reads a body into documents. The README section "Writing a recipe" gives a full example and the rules.

    • runRecipe(crawler, recipe, input) fetches the request of an input through the crawler and gives the documents of its capture. registerRecipe registers a recipe in a runtime of your own.
    • readJson(body, capture) reads a body as JSON in its declared encoding. A body that is not JSON throws an error that names the URL and the content type.
    • mode: "page" obeys robots.txt. mode: "api" is a documented API: robots.txt does not apply, and the pace (minInterval) does.
    • reindex reads the captures of each recipe again, and the time travel (at, versions, diff) works on its documents. A runtime with no recipe keeps the documents.
    • The extractor of a recipe checks each document. A document that is not valid, a document id with the prefix archive: and the kind archived make the extractor throw. The runtime reports the error.
    • When the extractor cannot read a stored copy, runRecipe asks the source one more time. A held-back document shows no title and only its structural metadata, unless userProvided.
    • With fallback: "archive", a recipe of the mode page gets an archived copy after a refusal. The page reader reads the copy, so the documents of the recipe come only from live captures.
    • A recipe cannot use a name of the crawler (RESERVED_RECIPES): page, archive-copy, archive-index, robots.txt, sitemap and feed.
  • The venue recipe. readVenue(crawler, url) reads the opening hours of a venue from its own site. It reads the JSON-LD and the text of the home page, and of the pages that most likely hold hours or a menu.

    • Each reading names its page, its document and its capture. The result gives the best reading, the best reading of the site with no guess (from_site), and the days where the readings disagree.
    • It reads an OpenStreetMap opening_hours value that the caller gives (osm). It sends no request to OpenStreetMap.
    • On a page that lists more than one location, it reads only the location that matches location. With name, it tells if the home page names the venue. requireName stops at a site that does not name it.
    • It gives the menu links and the phone, and it tells when the site moved to a different host.
    • venueReadingsOf reads one stored document or version with no request. compareHours compares a reading with the week that an application keeps.
  • The product recipe. readProduct(crawler, url) reads the schema.org Product data of a product page. It gives the name, the brand, the SKU, the GTIN, the price, the availability, the seller and the image.

    • A price is an amount and an ISO 4217 currency. price and price_to give the range of the variants. A list price and a struck-through price are not the price.
    • It picks the product of the page, not a related product on the page. It reads the variant that the URL names.
    • It reads a product that is larger than the JSON-LD of the index from the stored body. It renders the page once when the plain page has no Product data.
    • A shop that refuses the crawler gives wall: true and a note. productOf reads JSON-LD records with no request, and readAmount reads an amount as a shop writes it.
  • The library only. The command line and the MCP server do not change: the MCP server keeps its nine tools.

  • A failed question keeps the text held back. When the MCP client can ask the user about user_provided, but the question fails (a timeout, a lost connection or a cancel), the text stays held back. Before, the opt-in of the operator (--allow-user-provided) released it. That opt-in applies only to a client that cannot ask.

  • This version only adds to the API. Code that compiled against 0.1.1 or 0.1.2 compiles against this version. compat.test.ts (0.1.1) and compat-012.test.ts (0.1.2) are the proof. The capture log, the bodies and the capture ids do not change.

    • OpenedCrawler does not change. openCrawler gives a HybridCrawler: an OpenedCrawler with hybrid, embed, rankWithin and a find that takes SearchOptions.
    • PoliteCrawler has the optional hybrid, embed and rankWithin. ReadingIndex has the optional digests, and Found has the optional passage.
    • The class DocIndex has the new method digests. A subclass of your own with a member of the same name can conflict with it.
  • Hybrid search, opt-in. find(q, { rank: "hybrid" }) fuses the BM25 ranking with the ranking of the vectors of a local embedding model. The default ranking stays exact BM25.

    • Embedder is the extension point: { id, dimensions, maxInputTokens?, embed(texts, { signal, purpose }) }. The option embedder of openCrawler takes one.
    • transformersEmbedder uses transformers.js (@huggingface/transformers) in the process. The package is an optional peer (^3.0.0 || ^4.0.0), and it loads at the first text. The default model is Xenova/bge-small-en-v1.5.
    • The first use of a transformers.js model downloads it from the Hugging Face Hub. That download does not go through the polite crawler.
    • ollamaEmbedder sends the texts to a local Ollama server (POST /api/embed), with no new dependency. It accepts only a loopback address, unless allowRemote is true. Its errors say ollama serve and ollama pull <model>.
    • The vectors go into vectors.sqlite, a projection beside the index, with WAL and busy_timeout. The key of a row is the hash of the text, the chunk and the id of the embedder. Thus a reindex keeps each vector.
    • A chunk is a window of whole sentences that ends at a paragraph when it can. It fits the input of the model (512 tokens at most), with an overlap of 10 percent. Each hit gives the passage of its best chunk.
    • A search gives vectors to its BM25 candidates. crawler.embed({ budget }) and the command embed give vectors to each stored page. A held-back page does not go to the embedder, and no result gives it.
    • The fusion is reciprocal rank fusion with k = 60, over 50 BM25 candidates and 50 vector neighbors (HYBRID_DEFAULTS). Each one is an option of find and rankWithin.
    • Without an embedder, rank: "hybrid" rejects with NO_EMBEDDER. It does not change to BM25 in silence.
    • The command line has --embedder transformers|ollama, --embed-model, --ollama-url, --allow-remote-ollama, find --rank hybrid and embed. embed takes --budget, --max-docs and --kind.
    • The MCP tool crawl_find takes rank: "hybrid" only when the server has an embedder.
    • The search compares the question with each stored vector. The README gives the measured time: 82 ms for 89,100 chunks of 384 dimensions.
  • The benchmark. bench/find.mts --hybrid and the input hybrid of bench.yml time hybrid search with a fake embedder.

  • The daemon only adds to the API. Code that compiled against 0.1.2 compiles against this version, and compat.test.ts stays green. The capture log, the bodies and the capture ids do not change.

    • WatchRunOptions has the optional drain, and CrawlServerOptions has the optional tasks. Without tasks, the MCP server on the standard input and output does not change.
    • The daemon writes its own folder, <store>/daemon/, with state.json and mcp-token. The other files of the store do not change.
  • The daemon. polite-crawler daemon and startDaemon(options) check the watch list on a schedule. Each tick is one watch run, so each polite rule applies.

    • A due entry wakes the daemon at its time, with a random jitter after it (--tick, --jitter). A tick keeps its budget and its maximum (--tick-budget, --tick-pages). The entries that a tick leaves wait for the next tick.
    • The daemon writes each confirmed change as one JSON line, to the standard output or to --events <file>. onChange and --on-change <command> get each change. The command gets the event on its standard input, not in its command line.
    • At SIGINT or SIGTERM, the daemon starts no new check. The checks in progress get --grace to end, then they abort, and the daemon releases their leases.
    • polite-crawler daemon status reads <store>/daemon/state.json: the next due watches, the last tick, the tasks that run and the last error. It exits with 0 when a daemon operates on the store.
    • scheduleWatches gives the schedule over the watch list of a crawler of your own. watch.run takes drain: the run starts no new check, and the checks in progress end with their state.
    • The package installs no service. The README gives example files for systemd, launchd and the Task Scheduler of Windows.
  • MCP over local HTTP, with MCP tasks. daemon --mcp-http serves the nine tools over the Streamable HTTP transport, at http://127.0.0.1:9307/mcp.

    • Each request needs a bearer token. The daemon makes a new token at each start in <store>/daemon/mcp-token, for the owner only, or it reads --mcp-token-file. The check compares SHA-256 digests in constant time.
    • The server binds to a loopback address. A different host needs --allow-remote. On a loopback address, the server refuses a Host or an Origin header of a different site.
    • crawl_site and crawl_discover are MCP tasks, with the native tasks of the MCP SDK 1.32.1. A client gets a task id, polls the status, gets the result and can cancel the task. A client with no tasks gets the result in the call, with progress.
    • The library has startMcpHttpServer and mcpHttpHost in polite-crawler/mcp. The daemon reaches MCP through the seam DaemonOptions.mcpHost, and it loads the MCP SDK only for --mcp-http.
    • The MCP SDK marks its task API as experimental. When the SDK changes it, the tasks change with it.