Skip to content

LearnRetrieve

Phrase and negation search

Quoted phrases · Exclusion operators

Query operators that require words to appear together and in order ("jet charter") or exclude passages containing a word (-staging).

In DocSlurpGlossary entry

On this page

Phrase and negation operators give keyword search two precise controls. A quoted phrase requires words to appear next to each other in order: "operating margin" matches “the operating margin reaches 24%” but not “margin of the operating plan”. A minus sign excludes passages: forecast -draft drops every passage that mentions drafts.

Postgres’s websearch_to_tsquery, which accepts the syntax people already type into web search engines, turns "operating margin" -drafting into 'oper' <-> 'margin' & !'draft': “operating” immediately followed by “margin”, and no “drafting” (stemmed to draft). Phrase matching needs word positions in the index, which is why some lightweight BM25 indexes that store only counts can’t support it.

The gotcha: hybrid search ignores half of it

Operators mean something only to the keyword side. In hybrid search, the vector branch embeds the literal string, quotes and minus sign included, so -drafting adds the idea of drafts to the query vector. Draft passages excluded by keyword search can come right back through the vector branch and survive fusion. When an exclusion must hold, apply it as a metadata filter instead of a query operator.

In DocSlurp, queries containing quotes or a leading minus sign are sent to the Postgres keyword path, which honors both, instead of the native BM25 index, which would treat a quoted phrase as loose words and boost a -term instead of excluding it.

In DocSlurp

In DocSlurp

The keyword branch parses queries with Postgres websearch_to_tsquery, which honors quotes and -term; queries that use them skip native BM25, which cannot (nativeLexicalQuerySupported in core/server/src/services/search.ts). The vector branch ignores operators.

Sources

Jump to