Coverage for src/lilbee/retrieval/query/expansion.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-11-06 08:17 +0000

1"""Constants for LLM-driven query expansion, HyDE, and history condensation.""" 

2 

3from __future__ import annotations 

4 

5from lilbee.providers.base import ChosenSeed 

6 

7EXPANSION_PROMPT = ( 

8 "Generate {count} alternative search queries for the following question. " 

9 "Return ONLY the queries, one per line, no numbering or explanation.\n\n" 

10 "Question: {question}" 

11) 

12 

13EXPANSION_MAX_TOKENS = 200 

14 

15# HyDE writes one hypothetical answer passage to embed, which is a different 

16# shape of output from a list of query variants. Same number today, but tuning 

17# either one must not move the other. 

18HYDE_MAX_TOKENS = 200 

19 

20# The seed of the LLM steps of a search when the user sets none. An unseeded step 

21# samples new variants on every call, so the same query returns different rows. 

22SEARCH_SEED = ChosenSeed(42) 

23 

24CONDENSE_PROMPT = ( 

25 "Rewrite the follow-up question as one standalone search query, resolving " 

26 "pronouns and references using the conversation. Return ONLY the rewritten " 

27 "query, nothing else. If the question already stands alone, return it " 

28 "unchanged.\n\nConversation:\n{history}\n\nFollow-up question: {question}" 

29) 

30 

31CONDENSE_MAX_TOKENS = 120 

32 

33# Trailing history messages included in the condensation prompt (one 

34# ChatMessage each, so 6 is the last 3 user/assistant exchanges); older 

35# messages rarely change what a follow-up refers to and only add latency. 

36CONDENSE_HISTORY_TURNS = 6