API: ranking/passages

better-web-search-mcp


better-web-search-mcp / ranking/passages

ranking/passages#

Interfaces#

Passage#

Defined in: src/ranking/passages.ts:20

A scored span of text taken from a page.

Properties#

PropertyTypeDescriptionDefined in
endnumberCharacter offset of the passage end within the source content.src/ranking/passages.ts:26
scorenumberBM25 score against the query. Higher is more relevant.src/ranking/passages.ts:28
startnumberCharacter offset of the passage start within the source content.src/ranking/passages.ts:24
textstringThe passage text, trimmed.src/ranking/passages.ts:22

Variables#

MAX_PASSAGE_CHARS#

const MAX_PASSAGE_CHARS: 1200 = 1_200

Defined in: src/ranking/passages.ts:47

Hard ceiling on a single passage, in characters.

Paragraph splitting alone is not enough: plenty of extracted pages contain no blank lines at all, which made the whole page one passage. A cited “passage” was then the entire document, and web_research returned more text than reading the pages directly would have. Anything longer than this is windowed on sentence boundaries.


TARGET_PASSAGE_CHARS#

const TARGET_PASSAGE_CHARS: 500 = 500

Defined in: src/ranking/passages.ts:36

Target passage size in characters; paragraphs are packed up to this.

Functions#

rankPassages()#

rankPassages(passages, query): Passage[]

Defined in: src/ranking/passages.ts:153

Score passages against query with BM25 and return them ranked.

Passages that share no query term score 0 and are dropped: returning a passage with nothing in common with the question is what the old first-400-characters approach did.

Parameters#

ParameterType
passagesreadonly Passage[]
querystring

Returns#

Passage[]


selectPassages()#

selectPassages(content, query, limit?): Passage[]

Defined in: src/ranking/passages.ts:218

Select the passages of content most relevant to query.

Parameters#

ParameterTypeDefault valueDescription
contentstringundefinedThe extracted page content.
querystringundefinedThe user’s question.
limitnumber2Maximum passages to return.

Returns#

Passage[]


splitPassages()#

splitPassages(content): Passage[]

Defined in: src/ranking/passages.ts:71

Split content into passage-sized chunks on paragraph boundaries.

Markdown from the extraction pipeline is paragraph-separated, so blank lines are the natural split. Short paragraphs are packed together up to TARGET_PASSAGE_CHARS so a one-line heading is not its own passage, and an over-long paragraph is emitted whole rather than cut mid-sentence.

Parameters#

ParameterType
contentstring

Returns#

Passage[]


tokenize()#

tokenize(text): string[]

Defined in: src/ranking/passages.ts:58

Lowercase alphanumeric tokens, stop words removed.

Parameters#

ParameterType
textstring

Returns#

string[]