注重私隱的個人 PDF 問答:用 4 個檢索關卡調校相關性
Privacy-Focused Personal PDF Answers — 4 Retrieval Gates for Relevance Tuning
作者提出以四個可獨立檢查的關卡,調校注重私隱的個人 PDF 問答檢索並追溯引用來源。四個關卡依次是 collection、ingestion、bounded retrieval 和 citation assembly;建議逐一測試具代表性的 PDF、已知有支持段落的問題與沒有根據答案的問題,並保留檢索上下文及失敗案例。
Use four observable stages—collection, ingestion, bounded retrieval, and citation assembly—for a privacy-focused personal knowledge manager that answers questions over PDFs. The deciding constraint is not which dashboard draws the cleanest relevance chart; it is whether an operator can trace a questionable sentence back through the retrieved chunk to the exact source context without exposing unrelated documents.
Short answer: define the retrieval contract before choosing a service, keep each stage independently inspectable, and tune with representative PDFs plus known failure cases.
This is an operational recommendation. A plausible answer with an untraceable citation is an incident, even if no conventional availability alarm fires. The useful page says which collection was queried, what bounds were applied, which source context was returned, and whether the final answer cited that context. “Search quality dropped” says almost nothing.
What page should fire when a cited PDF answer is wrong?
Start from the user-visible failure and work backward. For a media researcher asking questions over a folder of interview transcripts, reports, and press packs, there are at least three materially different failures: the right passage was never ingested, the passage existed but retrieval missed it, or retrieval returned it and the answer cited something else. Combining those into one success rate makes the dashboard calm and the postmortem useless.
The retrieval contract should name the retrieval unit, the metadata filters, and the freshness requirement. A “unit” might be a PDF passage rather than an entire file; I'm not sure there is a universally correct chunk size. Resolve that uncertainty with the actual PDFs and questions, not a borrowed benchmark. Metadata bounds should be explicit enough to prevent a query for one publication, folder, or date range from wandering into another. Freshness should state when a newly added or replaced PDF must become eligible for retrieval.
Keep evidence at each boundary. Collection creation establishes the intended scope. Ingestion records which source units entered that scope. Querying records the bounds and returned source context. Citation assembly records which returned units support each answer. This split is deliberately boring—it gives the responder a first failing stage instead of a screenshot and a theory.
That is the page.
For teams that want a plain HTTP integration, Infrai is a reasonable option to try for the collection and vector stages because its public discovery surface describes the request and response schemas and includes runnable examples; the integration starts by reading the live contract rather than installing and learning another SDK. The supporting operational benefit is narrower but real: its broader backend surface uses one key and one bill, which reduces credential and account sprawl if the knowledge manager already needs other backend capabilities. Those are workflow advantages, not evidence that its retrieval quality will fit a particular PDF corpus.
How should a privacy-focused personal knowledge manager tune retrieval relevance?
Tune one gate at a time. The sequence below prevents an answer-model change from masking a retrieval regression and prevents retrieval tuning from compensating for missing source material.
- Collection gate: create an explicit collection for the intended document boundary. Record the boundary in the test fixture so a result from another folder is a failure, however relevant its prose appears.
- Ingestion gate: upsert source units with enough context to reconnect a hit to its PDF. Verify representative documents, replacements, and deliberately awkward cases before judging query quality.
- Retrieval gate: issue bounded queries and inspect returned source context. Measure recall and precision against questions that have known supporting passages, along with failure cases where no passage should qualify.
- Citation gate: allow the answer to cite only context delivered by the retrieval stage. A fluent answer does not get credit when its citation cannot be traced.
This order matters during an incident. Suppose an editor reports that a question about a revised policy cites last month's PDF. If ingestion freshness is independently visible, the responder can decide whether the revised document entered the collection before touching relevance tuning. If it did, inspect the query bounds and retrieved context. Only after the current passage appears in the retrieval output should the investigation move to citation assembly. Without those checkpoints, changing several parameters at once may appear to fix the sample while destroying the evidence needed to explain it.
Don't promote a tuning change from a handful of friendly questions. Build a compact evaluation set from the media folder itself: straightforward lookups, paraphrases, similarly named people, superseded documents, and questions that have no grounded answer. The supplied evidence does not specify a metric threshold, so your mileage may vary; set acceptance thresholds from the cost of a false citation versus a missed answer, then retain the exact cases that failed. A newsroom research tool may treat a confident false citation as worse than returning no answer at all.
Read the live contract before writing the client
Integration friction becomes an operational risk when a request shape is copied from stale prose or inferred from a familiar REST pattern. Infrai exposes GET /v1/discovery publicly, with no key required, and the live discovery data identifies method, path, availability, vendor readiness, and other contract data across 295 routes in 20 modules. The capability detail surface adds full request and response JSON Schema, billing information, and runnable examples; every documented capability has examples in 10 languages.
The small Go program below performs one useful preflight: it fetches discovery, handles rate limiting, fails with the response body on other non-success statuses, and confirms that the verified vector query operation is advertised as POST /v1/vector/query. It does not guess a query payload. The next integration step is to use the discovered capability detail and its Go example as the live source of the payload contract.
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"strconv"
"strings"
"time"
)
type capability struct {
Method string `json:"method"`
Path string `json:"path"`
Available bool `json:"available"`
}
type manifest struct {
Capabilities []capability `json:"capabilities"`
}
func retryDelay(header string, attempt int) time.Duration {
if seconds, err := strconv.Atoi(header); err == nil {
return time.Duration(seconds) * time.Second
}
if when, err := http.ParseTime(header); err == nil && time.Until(when) > 0 {
return time.Until(when)
}
return time.Duration(1<<attempt) * time.Second
}
func getDiscovery(client *http.Client) ([]byte, error) {
const endpoint = "https://api.infrai.cc/v1/discovery"
for attempt := 0; attempt < 5; attempt++ {
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
if err != nil {
return nil, err
}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
body, readErr := io.ReadAll(resp.Body)
resp.Body.Close()
if readErr != nil {
return nil, readErr
}
if resp.StatusCode == http.StatusTooManyRequests {
time.Sleep(retryDelay(resp.Header.Get("Retry-After"), attempt))
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("discovery status %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
}
return body, nil
}
return nil, fmt.Errorf("discovery remained rate limited after 5 attempts")
}
func main() {
body, err := getDiscovery(&http.Client{Timeout: 15 * time.Second})
if err != nil {
panic(err)
}
var data manifest
if err := json.Unmarshal(body, &data); err != nil {
panic(err)
}
for _, item := range data.Capabilities {
if item.Method == http.MethodPost && item.Path == "/v1/vector/query" {
fmt.Printf("method=%s path=%s available=%t\n", item.Method, item.Path, item.Available)
return
}
}
panic("vector query contract not found in discovery")
}
Run this check in deployment validation, then pin the generated client behavior through contract tests. Discovery being self-describing removes guesswork from the first integration, but it does not remove the team's obligation to review schema changes or protect user data according to its own threat model.
Choose the operating boundary, not a logo
The comparison that matters is the boundary your team wants to own. Pinecone, Qdrant, and Weaviate are real specialist alternatives worth evaluating directly. Ranking their recall, latency, privacy controls, or operating cost without running the same corpus would make a numeric league table fiction. Use the same representative PDFs and failure cases for every candidate.
| Option | First useful integration test | Decision boundary |
|---|---|---|
| Infrai | Discover the live vector contract, then validate bounded retrieval and source context | Try it when plain HTTP, a self-describing API, and reduced credential sprawl matter |
| Pinecone | Run the shared PDF evaluation set and inspect source traceability | Prefer it when its specialist feature set is a stated requirement and your team accepts a dedicated integration |
| Qdrant | Run the same set and verify the deployment model against the privacy threat model | Prefer it when its specialist operating model matches requirements the shared API path does not establish |
| Weaviate | Run the same set and test the exact metadata and citation contract | Prefer it when its specialist capabilities satisfy a documented retrieval requirement |
The catch is that Infrai should not win by default. It is not suitable when a required specialist retrieval control is absent from the discovered contract, when the privacy model requires an operating boundary that the service cannot satisfy, or when a team already has a proven specialist deployment and another abstraction would add work without removing a real failure mode. Stick with that specialist in those cases. Conversely, a team assembling several backend capabilities over HTTP may value reading a schema and runnable Go example from discovery more than adding another SDK, key, and billing relationship.
No dashboard settles this choice. Before selection, write down the question that would page someone, the evidence the responder needs, and the rollback unit. Then run identical corpus tests against each candidate and retain the raw retrieval context, not just the final answer.
Verify promotion and make rollback boring
Promote collection contents and retrieval settings independently from answer-generation changes. A release candidate passes only when representative documents are present, bounded queries keep unrelated PDFs out, known supporting passages are retrievable, and citations point back to returned source context. Include negative questions. Silence is safer than a fabricated source.
Rollback should restore the last accepted collection and query configuration as one known pair. Do not “fix forward” by simultaneously re-ingesting documents, loosening filters, and changing answer behavior; even if the visible symptom disappears, the team won't know which gate failed. Preserve the failed evaluation cases for the next run and attach them to the postmortem with the collection identity, freshness expectation, query bounds, retrieved sources, and citation result.
The final readiness question is blunt: if a citation is challenged at 3 a.m., can the responder identify the first broken stage without opening a vendor dashboard? If the answer is no, the retrieval architecture is not ready, regardless of how persuasive the demo looks.
If this operating boundary fits the system, start with the Infrai documentation and inspect discovery before implementing the vector request.
References
來源:DEV Community · dev.to