sdk-python icon indicating copy to clipboard operation
sdk-python copied to clipboard

strands-mcp: search quality and ergonomics improvements (tracking)

Open yonib05 opened this issue 4 months ago • 3 comments

Tracking issue for a set of search quality and ergonomics improvements to the strands-mcp docs server, which is moving into this repo via #3300. Findings come from a code review plus empirical testing of the search index against the live llms.txt (763 documents).

Summary of findings

The headline issue is that search is effectively title-only: documents are indexed with empty content at startup and the index is never updated when pages are fetched, so all of the Markdown-aware scoring in the indexer is dead code and body-only queries (e.g. "guardrail", "temperature") return zero results. The remaining items cover ranking quality, tool ergonomics for LLM consumers, error handling, and configurability.

Each improvement is tracked as a sub-issue below. The plan is to pick them up one at a time as focused PRs.

Suggested priority order

  1. Index real document content (the core bug; everything else matters less until this is fixed)
  2. Stemming and token normalization
  3. Ranking user guides above API reference pages
  4. Docstring and README accuracy (score contract, content-search claims)

The rest are smaller quality and robustness fixes that can be picked up in any order.

Verification notes

Behavior was verified by running the actual IndexSearch against the live index:

  • Index contains only 831 distinct tokens for 763 docs (title tokens only)
  • After hydrating a 49,700 char page, the indexed Doc.content is still empty
  • "streaming" returns 3 results, "stream" returns 0; "guardrails" returns 3, "guardrail" returns 0
  • "how do I use structured output" ranks the API module page (score 750) far above the user guide (score 93)

yonib05 avatar Jul 17 '26 13:07 yonib05

Forward-linking an older report that is about to get lost: strands-agents/mcp-server#30 by @clareliguori (Jan 5). That repo is now archived, so the issue can no longer be commented on or fixed in place, but it is the same defect this tracker covers - from the opposite direction.

#30 reported that search_docs never surfaces API reference pages: the query "Agent class constructor parameters inputs" returned Agent2Agent (650), Multi-agent Patterns (108), CLI Reference Agent (108) - and no API page at all. This tracker's verification notes report the inverse: "how do I use structured output" ranks the API module page (score 750) far above the user guide (score 93), and priority 3 is "ranking user guides above API reference pages".

Those look contradictory but they are the same mechanism, so a fix aimed at only one will regress the other.

Root cause

_calculate_md_score scores title matches with title_lower.count(token) (indexer.py). str.count is a substring count, while index membership (doc_indices) uses the word tokenizer [A-Za-z0-9_]+. So a doc is only reachable by whole token, but once reachable its TF is inflated by every substring occurrence - and with content empty at startup the title boost is the maximum _TITLE_BOOST_EMPTY = 8.

API entries in llms.txt are dotted module paths, which repeat the module name. Ranking therefore turns on how many times a query token appears as a substring of the title string:

Query Title substring count x8
structured / output strands.tools.structured_output.structured_output_tool 2 each 16 each -> API wins
agent strands.agent.agent 2 16
agent Agent2Agent (A2A) + variants 6 48 -> A2A wins

When the query happens to echo the module path ("structured output"), the API page dominates. When it does not ("class constructor parameters inputs"), the API page loses to any title that merely repeats "agent" - which is #30 exactly. The other four tokens in that query match nothing in any title, because content is not indexed (#3321).

So #3321 is upstream of both. Once bodies are indexed, "constructor"/"parameters" can hit the actual API page. I would suggest the substring-vs-token TF inconsistency be fixed in the same pass, otherwise BM25 term frequencies inherit the same inflation.

Two smaller notes

  • The URL cited in #30 (/latest/documentation/docs/api-reference/python/agent/agent/index.md) now 404s. API reference moved to /docs/api/python/strands.agent.agent/index.md. The current llms.txt does index them - 439 entries under ## Api Python / ## Api TypeScript - so "not being indexed" is no longer the problem; ranking is.
  • strands-agents/mcp-server#40 (@dosvk, BM25 + hydration indexing) is open against the archived repo and can no longer merge there. It looks like it was stranded by the archive and probably needs re-targeting at strands-mcp/ in this repo.

Verified against the live https://strandsagents.com/llms.txt (863 lines) and strands-mcp/src/strands_mcp_server/utils/{indexer,cache,text_processor}.py on main today. The table above is derived by hand from the scoring code, not from running the index - worth a quick confirmation before anyone leans on the exact numbers.

@clareliguori - flagging since #30 is now unreachable in the archived repo; this tracker is where it lives on.

Ashutosh0x avatar Jul 29 '26 03:07 Ashutosh0x

Thanks @Ashutosh0x — nice write-up, and agreed that #3321 is the shared root cause.

Quick status correction: the old mcp-server#40 has already been re-targeted here as #3502 (per @mkmeral's request when the repo was archived). It does exactly the index-on-hydration fix you point to — so "constructor"/"parameters"-style queries can reach API pages once bodies are indexed. Note I dropped the BM25 swap from that PR after review showed it regressed ranking on the live corpus; #3502 is now purely hydration + thread-safety + atomic index updates, no scoring redesign.

On the substring-vs-token TF inflation in _calculate_md_score (title_lower.count(token) counting substrings while doc_indices tokenizes on words): that looks like a real, separate defect, and I agree it should be fixed before/with any BM25 work so the inflation isn't inherited. Id suggest keeping it out of #3502 though — that PR is intentionally minimal so it can merge as the clean #3321 fix, and a TF/ranking change deserves its own PR with a before/after relevance benchmark (the same kind of graded-query check that caught the BM25 regression). Happy to pick that up as a follow-up once #3502 lands. (Also +1 that the numbers in the table are worth confirming against a live index run before relying on them.)

dosvk avatar Jul 29 '26 03:07 dosvk

Thanks @dosvk - and noted on #3502, my "stranded" comment was out of date. Good that it was re-targeted; agreed it should stay minimal as the clean #3321 fix, and that the TF change belongs in its own PR with a graded-query benchmark. That one is yours, I am not going to duplicate it.

Since we both flagged that my table needed confirming: I ran it. And I was wrong on the numbers - reporting that first.

Correction to my table

I derived those scores by hand from _calculate_md_score and ignored both IDF and the extra variants index_title_variants generates. Real figures below. The mechanism and the ordering conclusion hold, the magnitudes do not.

Method

Real IndexSearch and text_processor from main, unmodified, replicating cache.load_links_only() against the live llms.txt. Only doc_fetcher was stubbed (no network). Python 3.12.

Corpus today: 794 docs, 848 distinct tokens (your notes say 763/831 - it has grown, which is why absolute scores differ from yours).

#30's query: "Agent class constructor parameters inputs"

200.73  strands.agent.a2a_agent
133.82  agent-to-agent
133.82  strands.agent.agent_result

strands.agent.agent - the actual Agent class page - ranks #15 of 32, score 66.91. So #30 reproduces exactly on today's index: the page the user wanted is buried under an A2A module and a user guide.

The reason is starker than I described. Per-token reach:

token docs matched
agent 32
class 0
constructor 0
parameters 0
inputs 0

Four of five tokens match nothing, so ranking is decided entirely by agent. That is #3321 in its purest form, and it is the strongest argument I have seen for your priority order - #3502 alone should move this a long way.

The substring inflation, measured

strands.agent.agent      index_title='strands.agent.agent'
                         substring count('agent')=2   token count=2

strands.agent.a2a_agent  index_title='strands.agent.a2a_agent strands.agent.a to a_agent Strands.Agent.A2A Agent'
                         substring count('agent')=6   token count=4

So it is real but smaller than I implied: 6 vs 4, a 50% inflation, not the 3x my table suggested. Note the (\w)2(\w) -> \1 to \2 transform in index_title_variants is doing much of the work here by minting extra variants.

Your other numbers

  • "how do I use structured output": API page 377.64, user guide "Structured Output" 94.41. Your guide figure (93) matches almost exactly; the API figure differs from your 750, again consistent with the corpus having grown.
  • Stemming: streaming -> 3, stream -> 0, guardrails -> 3, guardrail -> 0. Reproduces exactly.

Offer

The harness is ~40 lines, stdlib only, no network, and runs the real index in about a second. That is close to the before/after relevance check you said the TF PR needs. Happy to contribute it as a small tests/ benchmark with a set of graded queries so #3502 and any later ranking change can be measured rather than argued about - as a separate PR, whenever it is useful to you. Just say if you would rather own that too.

Ashutosh0x avatar Jul 29 '26 04:07 Ashutosh0x