API: ranking/passages
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#
| Property | Type | Description | Defined in |
|---|---|---|---|
end | number | Character offset of the passage end within the source content. | src/ranking/passages.ts:26 |
score | number | BM25 score against the query. Higher is more relevant. | src/ranking/passages.ts:28 |
start | number | Character offset of the passage start within the source content. | src/ranking/passages.ts:24 |
text | string | The passage text, trimmed. | src/ranking/passages.ts:22 |
Variables#
MAX_PASSAGE_CHARS#
constMAX_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#
constTARGET_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#
| Parameter | Type |
|---|---|
passages | readonly Passage[] |
query | string |
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#
| Parameter | Type | Default value | Description |
|---|---|---|---|
content | string | undefined | The extracted page content. |
query | string | undefined | The user’s question. |
limit | number | 2 | Maximum 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#
| Parameter | Type |
|---|---|
content | string |
Returns#
Passage[]
tokenize()#
tokenize(
text):string[]
Defined in: src/ranking/passages.ts:58
Lowercase alphanumeric tokens, stop words removed.
Parameters#
| Parameter | Type |
|---|---|
text | string |
Returns#
string[]