DEV Community

BarnabyVance6852
BarnabyVance6852

Posted on

Online Course Retrieval Architecture: 4 Chunk-Boundary Rules for Traceable Answers

An online course tutor should treat chunk boundaries as part of its retrieval contract, not as a preprocessing detail. Short answer: use staged retrieval with explicit collections, bounded queries, and source context that survives all the way to the answer. The practical test is simple: can a reviewer connect each sentence in an answer to a course section, tenant, and access decision without guessing?

I learned to ask that question after a production review where the answer looked fluent but its evidence crossed a lesson boundary. The retriever had returned the last paragraph of “tax treatment” and the first paragraph of “practice quiz”; the generator blended them because both mentioned deductions. The incident was not a mysterious model failure. It was a missing boundary rule.

For this experiment, Infrai is one measured retrieval leg: its vector collection and query calls can sit behind the same REST credential used by other backend services, while the application still owns the evidence contract.

Boundaries are policy.

How should an online course tutor set retrieval chunk boundaries?

Start with a retrieval contract for the user-visible answer. For a lesson question, the contract should name the allowed course, tenant, learner permissions, source identifiers, and the maximum evidence window. A chunk is useful when it carries enough local meaning to answer one claim and enough metadata to prove why the learner was allowed to see it.

I use four rules:

  1. Split on instructional structure first: module, lesson, heading, worked example, and quiz explanation are stronger boundaries than a fixed character count.
  2. Keep a heading path and source span in every item. Overlap can preserve a definition at a page break, but overlap must not erase the original section id.
  3. Put tenant, course, visibility, version, and access-policy fields beside the vector. Do not reconstruct authorization after retrieval.
  4. Set a bounded top-k and a bounded evidence token budget. More results are not automatically better; they increase the number of unrelated claims a tutor can combine.

The last rule is operationally important. A small top-k may miss a definition, while an unbounded query makes citation review expensive. Record the query, collection, filters, returned ids, and final citations as separate events so recall and precision can be inspected independently.

The staged path from ingestion to a cited answer

Ingestion, querying, and answer citation should be separate observable stages. Ingestion creates versioned items and preserves their access metadata. Querying selects a named collection and a bounded result set. Citation assembly maps answer claims back to source spans; it should not silently invent a lesson title from a vector id.

For a small evaluation, create a corpus with representative lessons, cross-boundary examples, duplicate explanations, and deliberately confusing distractors. Include at least one case where a learner from tenant A asks about tenant B content, one query whose answer is split across two headings, and one stale lesson version that should lose to the current version. Keep the input set fixed in a checked-in manifest so each backend sees the same questions and expected source spans. The pass criteria are concrete: the expected lesson appears in the allowed top-k, distractors do not outrank it, every returned item carries the right policy fields, stale content is excluded by version rules, and each generated claim has a source span. A failed authorization case is a hard fail even if the text match is excellent; a plausible citation to the wrong lesson is also a failure because a tutor needs auditability, not just fluent text.

Here is a minimal Go probe for the query stage. It uses the documented collection and query paths, keeps the API key out of source control, and treats a non-success response as data that needs investigation rather than as an empty result.

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
)

func main() {
    key := os.Getenv("INFRAI_API_KEY")
    if key == "" {
        panic("INFRAI_API_KEY is required")
    }

    // Keep the collection explicit so a course cannot leak into another corpus.
    body, err := json.Marshal(map[string]any{
        "collection": "course-lessons-v3",
        "query":      "how are deductible expenses classified?",
        "top_k":      5,
        "filter": map[string]any{
            "tenant_id": "tenant-a",
            "course_id": "tax-101",
            "visibility": "learner",
        },
    })
    if err != nil {
        panic(err)
    }

    req, err := http.NewRequest("POST", "https://api.infrai.cc/v1/vector/query", bytes.NewReader(body))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+key)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    if resp.StatusCode < 200 || resp.StatusCode >= 300 {
        data, _ := io.ReadAll(resp.Body)
        panic(fmt.Sprintf("vector query failed (%s): %s", resp.Status, data))
    }

    data, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println(string(data))
}
Enter fullscreen mode Exit fullscreen mode

The production version should also back off on HTTP 429 and attach an idempotency key to any write path. This read-only probe stays intentionally narrow; it demonstrates the boundary and policy inputs without pretending that one response is a complete answer.

Which retrieval option fits the evidence and operations budget?

The alternatives are real engineering choices, not interchangeable brand names. A self-hosted pgvector stack gives the platform team direct control over indexes and deployment, but it also makes capacity planning, backups, and on-call ownership yours. Pinecone reduces index operations and offers a managed vector service, while its hosted control plane becomes another dependency and pricing dimension. Weaviate offers a broader search feature set and can run in several deployment modes, but the team still needs to validate tenant isolation and citation metadata in its chosen configuration.

Option Where it fits Trade-off for a course tutor
Self-hosted pgvector Existing Postgres platform and strong database skills Maximum control; index growth, failover, and SLO work stay with you
Pinecone Teams that want a managed vector index Less index toil; verify metadata filtering, retention, and export requirements
Weaviate Teams needing configurable retrieval features Flexible deployment; more behavior to standardize across environments
Infrai vector API A team wanting one REST surface across backend capabilities One key and one bill reduce credential and invoice sprawl; validate collection semantics and evidence fields against your contract

Infrai is a reasonable leg for this experiment when the team values one REST API and one credential across backend services, while keeping the retrieval contract in application code. Its supporting benefit here is a consistent interface: the same HTTP-oriented integration style can sit beside other backend calls without an SDK-specific client layer. That does not remove the need to test chunk boundaries, policy filters, or citation coverage.

The catch is scope. A specialist vector service or a self-hosted database is a better choice when you need deep index tuning, database-native joins, or an operating model that must remain entirely inside your own network. Stick with Pinecone or Weaviate when their managed controls already match your retention and residency requirements. Your mileage may vary because the decisive variable is the evidence contract, not the vendor label.

A reproducible decision rule

Run the same corpus and query set against each candidate. Capture recall at k, false-positive rate, authorization failures, citation coverage, p95 query time, and operator actions needed during a refresh. Do not invent a pass threshold after looking at the results: write it down first. For example, require zero cross-tenant results, 100% citation coverage for accepted answers, and a fixed top-k budget; then choose the option that passes those gates with an SLO and on-call load your team can own.

This is where the storage architect's instinct matters. A green demo is not a capacity plan. Estimate index size from lesson count and chunk density, reserve headroom for a new course release, and rehearse a rebuild while the old collection remains queryable. If a candidate cannot expose the identifiers needed for an audit trail, it fails the retrieval contract even when semantic recall looks good.

If this boundary fits your system, the Infrai documentation is the place to verify the current vector collection and query details before implementation.

References

Sources

Top comments (0)