Alternative A: Keep the current PostgreSQL full‑text
Flow
raw chunkText
-> plainto_tsquery
-> search_tsv @@ query
-> ts_rank_cd
-> return top JSONLAdvantages
- It is already implemented.
- It can be done with PostgreSQL alone.
- The infrastructure is simple.
- It matches directly with tables that already have
search_tsv.
Disadvantages
- It is not BM25.
- It is weak with long code chunks.
- Conditions created by
plainto_tsquerycan become overly narrow. - There is a lot of code token noise.
- It cannot perform semantic search.
- Even a slight change in chunk splitting can result in zero matches.
Expected Issues in the Standard Chunk
The standard chunk contains the following tokens all at once.
func
process
delta
velocity
vector2
zero
input
is_action_pressed
move_right
move_left
normalized
animatedsprite2d
play
stop
position
clamp
screen_sizeAll of these tokens must be present together in a single JSONL row, otherwise the search results may be missing.
PoC Simulation
Assume the reference chunk is passed directly to /api/retrieve.
Input:
chunkText = entire _process(delta) function bodyThe current method converts this input to plainto_tsquery('simple', chunkText).
Expected query characteristics:
func & process & delta & var & velocity & vector2 & zero
& input & is_action_pressed & move_right & move_left
& length & normalized & speed & animatedsprite2d
& play & stop & position & clamp & screen_sizeAt this point, a problem occurs if the actual related document is split into two chunks as shown below.
docs chunk A:
Input.is_action_pressed("move_right")
Input.is_action_pressed("move_left")
velocity.normalized() * speed
$AnimatedSprite2D.play()
$AnimatedSprite2D.stop()
docs chunk B:
position += velocity * delta
position = position.clamp(Vector2.ZERO, screen_size)If a person looks, both A and B are related.
However, if a full-text query demands too many tokens at once, it can result in something like the following.
docs chunk A:
animatedsprite2d = present
is_action_pressed = present
move_left/move_right = present
clamp = absent
screen_size = absent
position.clamp = absent
=> query does not satisfy the whole condition
docs chunk B:
clamp = present
screen_size = present
position = present
animatedsprite2d = absent or weak
move_left/move_right = absent
is_action_pressed = absent
=> query does not satisfy the whole conditionVisible forms of failure:
Search results 0 items
or return only a very narrow chunkIn this method, it is difficult to distinguish whether a search failure is due to “no basis in the document” or “the query conditions being too strict”.
Logs to Verify in PoC
When testing this alternative, you should not look only at the results.
You need to show the following values together.
1. raw chunkText
2. query created with `plainto_tsquery`
3. list of tokens included in the query
4. number of rows returned
5. if zero results, which token made it too narrowExpected Observation:
The longer the raw chunk, the longer the query becomes, and if the related documents are split across multiple chunks, the results are missing.Judgment
PoC baseline is usable
Final search strategy is a discard candidateThe judgment of the original note is close to “It’s better to redo it.”