kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Return `search_level` in content node search responses

Open akolson opened this issue 1 month ago • 4 comments

Overview

The Learn search page will show different sections depending on how a search ran: with a language model, with vector search, or with keyword search only. Currently, the content node search response does not say which of these ran. This task adds a search_level field to the response of every search request, and makes Learn read it. On a device without models, the value is always "keyword", and search looks and behaves exactly as it does now.

This is the first task in the breakdown of #15567, and the later tasks build on this field.

Complexity: Low Target branch: develop

Context

Search in Learn uses the content node list endpoint. The learner's text goes in search for autocomplete, or in question for a full search. Currently, both run the same keyword search on titles and descriptions.

The paginated response, built by OptionalContentNodePagination, has three fields: more, results and labels (get_paginated_response). Its API schema lists the same three (get_paginated_response_schema). The same response class serves every paginated content node list, including browsing a folder, which has none of the search query parameters (search, question and keywords).

Search on a remote device, through Explore Libraries, works in three steps:

  1. Learn sends the search to the learner's device.
  2. The learner's device passes the request on to the remote device's public endpoint, PublicContentNodeViewSet. That endpoint builds its response with PublicContentNodePagination, a subclass of OptionalContentNodePagination.
  3. The learner's device returns the remote device's response to Learn unchanged.

So for a remote search, the remote device decides whether Learn receives a search_level. A device older than 0.20.0 sends none. Those devices also do not know the search and question parameters, so the learner's device sends keywords to them instead (contentnode_previously_renamed_params).

Learn reads the response in useBaseSearch.

"The front-end contract" in #15567 defines search_level and its three values.

The Change

  • Every content node search response includes search_level. A request is a search when search, question or keywords has a non-empty value, for example GET /api/content/contentnode/?search=fractions. These are the three query parameters that the content node search filter reads.
  • With no language model and no vector search set up, search_level is always "keyword". Later tasks (#15731, #15743) set "lm" and "vector".
  • The API schema lists search_level with its three values, and states that it appears only for searches.
  • The public endpoint, PublicContentNodeViewSet, returns search_level in the same way.
  • useBaseSearch exposes the search_level of the search that is showing. A response without one, for example from a remote device without this change, counts as "keyword".
  • Nothing visible changes in Learn. Later tasks, starting with #15744, use the value to show or hide sections.

How to Get There

  1. Start the dev server, and import at least one channel.
  2. Sign in as a learner, and open the Library page in Learn.
  3. Open the browser's developer tools on the Network tab.
  4. Type in the search bar, then press Enter. The autocomplete request carries search, and the full search request carries question. Both responses show "search_level": "keyword", next to results, more and labels.
  5. Open a channel and browse a folder without searching. The response for that folder has no search_level.

To check a remote search, use Explore Libraries to search a second Kolibri device. A device that runs this change sends search_level. An older one sends none, and Learn treats it as "keyword".

Out of Scope

  • Setting "lm" or "vector". The pipeline adapter interface (#15731) sets "lm", and the vector search path (#15743) sets "vector".
  • Any visible change in Learn. The results page (#15744) shows or hides sections.
  • The search status request (#15738).
  • Changes to how search matches resources, including the keyword search itself.
  • Searches that use a remote device's language model. This is still an open question in #15567, under "Search on another device".

Acceptance Criteria

General

  • [ ] ?search=fractions, ?question=fractions and ?keywords=fractions each return "search_level": "keyword".
  • [ ] A request without these query parameters, or with an empty value such as ?search=, returns no search_level.
  • [ ] The public endpoint behaves in the same way.
  • [ ] The API schema documents search_level, its three values, and that it appears only on searches.
  • [ ] useBaseSearch gives "keyword" when a search response has no search_level, and no value when no search is showing.
  • [ ] Search results, labels and paging do not change.

Testing

  • [ ] Backend tests cover each General criterion, for the local and the public endpoint.
  • [ ] Frontend tests cover a response with search_level, a response without it, and no search showing.

Testing

This task has no visible result of its own, so QA does not test it. The reviewer checks the automated tests and the API responses, following "How to Get There".

Existing tests to extend:

  • kolibri/core/content/test/test_content_app.py and kolibri/core/content/test/test_search.py, for content node search
  • kolibri/core/content/test/test_public_api.py, for the public endpoint
  • packages/kolibri-common/composables/__tests__/useBaseSearch.spec.js, for Learn

Run them with:

pytest kolibri/core/content/test/test_content_app.py kolibri/core/content/test/test_search.py kolibri/core/content/test/test_public_api.py
pnpm test-jest packages/kolibri-common/composables/__tests__/useBaseSearch.spec.js

AI usage

I used Claude Code to draft this issue from my breakdown of #15567. I made the scope decisions, and I reviewed and edited the draft.

akolson avatar Nov 03 '26 08:11 akolson

assign

ArpitaSamanta10 avatar Nov 09 '26 06:11 ArpitaSamanta10

Hi! 👋

Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.

We really appreciate your willingness to help. 😊

Are you preparing for Google Summer of Code? See our GSoC guidelines.

learning-equality-bot avatar Nov 09 '26 06:11 learning-equality-bot

Plan: Paginated content node search responses carry search_level (always "keyword" for now), and useBaseSearch exposes it as searchLevel.

  • [ ] Backend — search_level on paginated search responses and in the schema
  • [ ] Frontend — useBaseSearch exposes searchLevel
  • [ ] Self-review the produced code

Assumptions — the issue did not settle these; say so if one is wrong.

  • A search without max_results stays a bare list with no search_level, though the criterion writes ?search=fractions without it: the issue places the field "next to results, more and labels", and test_content_app.py:1977-2052 asserts bare lists for unpaginated searches. If wrong, those responses become objects and every bare-list caller and test breaks.
  • The kolibri/client mock can answer ContentNodeResource.list inside useBaseSearch.spec.js once the real list is restored; not run, this session had no node_modules. If wrong, the searchLevel tests fall back to the file's ContentNodeResource.list.mockReturnValue, and the PR body says so.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 25 '26 22:11 rtibblesbot

Decided without asking; a reply here changes it.

  • Pre-upgrade search ETags stay as they are: no cache-key change and no follow-up issue.
    • What happens: the ETag is the content cache key alone (kolibri/core/content/utils/cache.py:43) and no 0.20 upgrade hook bumps it, so a browser copy cached before the upgrade revalidates to 304 and keeps its body without search_level until content changes. test_contentnode_etag passes on the branch.
    • No user is affected: the issue defines a response without search_level as "keyword", the only level this branch sends, and useBaseSearch applies that default. The cached results came from keyword search, so the label is true.
    • "The branch exposes it" pointed to fixing here. "Edge case with no affected user" and "a remedy nothing depends on" outweighed it: the fix changes ETags on the channel metadata, content node tree and import metadata endpoints, and on ETags proxied from peers, for no visible difference.
    • Reviewers reading raw responses use a new search term or disable the browser cache; the PR body says so.
    • The content-only ETag starts to matter when a search response can change without a content change; a note saying so is drafted for #15731.

Written by rtibblesbot, an LLM-based coding agent.

rtibblesbot avatar Nov 26 '26 03:11 rtibblesbot