Skip to content

Feature: Cross-Document Semantic Search & “Ask Your Workspace” (RAG across all uploads) #21

Description

@hoangsonww

Summary

Enable semantic search and grounded Q&A across all documents in a user’s library (web, mobile, and VS Code extension). The feature indexes uploaded content into a vector store, supports filters (type, tags, date), and powers an “Ask Your Workspace” chat that returns cited answers with source snippets.


Motivation

  • Users upload many files; today they must open each to find answers.
  • RAG across the user’s corpus unlocks instant insights, better chat grounding, and stronger reuse of prior uploads.
  • Pairs well with existing Redis/RabbitMQ infra for indexing and caching; exposes clean GraphQL/REST for all clients (web, mobile, extension).

Goals

  1. Semantic Search across a user’s entire library with filters (file type, tags, date range).
  2. Workspace Q&A: natural-language questions with answers grounded in top-k passages + inline citations.
  3. Citations UI: expandable snippets showing exact source, page/section, and quick-open.
  4. Indexing Pipeline: chunking, dedup (content hash), incremental updates on new/edited docs.
  5. Privacy & Isolation: strict per-user namespaces; no cross-tenant leakage.
  6. VS Code Extension integration: global search & “Ask Workspace” panel.
  7. Admin/Debug endpoints: reindex status, queue depth, last error.

Non-Goals (this issue): org-wide sharing, external drives sync, full OCR/table extraction (can be follow-ups).


Acceptance Criteria

  • A global search bar (web) returns relevant results in <1.5s p95 for top-k=10 on a typical user library (≤ 500 docs).
  • Clicking a result opens the doc page scrolled to the cited passage (or shows an inline snippet).
  • “Ask Your Workspace” answers stream tokens and include at least 3 citations when available; if no sources found, return a clear “no sources” state (no hallucinated content).
  • Filters: MIME (pdf/docx/txt), tags, created/updated date range.
  • Works in dark/light modes; fully keyboard accessible (enter to search, arrows to navigate results).
  • Extension exposes the same search & Q&A (no extra login beyond current app auth).
  • Telemetry events emitted (see Analytics).

UX Notes

  • Global Search in header; results list with snippet, confidence, tags, and file icon.
  • Q&A Panel (ChatModal): a toggle “Search scope: current doc | all docs”. Answers include numbered citations [¹][²][³]; clicking jumps to snippet.
  • Empty State: suggests uploading docs or widening filters.

API & GraphQL (proposed)

REST (Express):

POST /v1/search/semantic
body: { query: string, topK?: number, filters?: { mimeTypes?: string[], tags?: string[], dateFrom?: string, dateTo?: string } }

POST /v1/qa/workspace
body: { question: string, topK?: number, filters?: {...}, stream?: boolean }

GET  /v1/index/status
POST /v1/index/reindex   # optional: specific docIds or full user reindex

GraphQL:

type SearchHit {
  docId: ID!
  title: String!
  snippet: String!
  score: Float!
  location: String    # page/section/offset
  mimeType: String
  tags: [String!]
  updatedAt: String
}

type QAChunk {
  text: String!
  citations: [SearchHit!]!
}

type Query {
  workspaceSearch(query: String!, topK: Int, filters: FiltersInput): [SearchHit!]!
  workspaceQA(question: String!, topK: Int, filters: FiltersInput): [QAChunk!]!
}

input FiltersInput {
  mimeTypes: [String!]
  tags: [String!]
  dateFrom: String
  dateTo: String
}

Response example:

{
  "answer": "Project X uses a zero-downtime rollout via NGINX and Kubernetes.",
  "citations": [
    { "docId": "abc123", "title": "kubernetes/README.md", "snippet": "NGINX as reverse proxy...", "location": "L45-L67" }
  ]
}

Indexing Pipeline

  • Chunking: 800–1200 tokens, 150–200 overlap; include docId, page/section, content hash.
  • Embeddings: pluggable provider; store dim in config (e.g., 1536).
  • Vector Store: start with FAISS/pgvector (self-host) and adapter pattern for Pinecone/Weaviate later.
  • Ingestion: PDFs/Docx → text; reuse existing upload flow; enqueue index_document via RabbitMQ.
  • Dedup: skip chunks with unchanged hash.
  • Metadata: MongoDB holds doc + chunk metadata; Redis caches top-k for frequent queries.

Security & Privacy

  • Verify Firebase/JWT at gateway; namespace vectors by userId.
  • Encrypt at rest when supported; redact secrets/PII heuristically (optional flag).
  • Rate-limit search/QA to prevent abuse.

Performance

  • Async indexing; UI shows per-doc index status.
  • Redis cache for popular queries (TTL 15–60m).
  • Stream answers over SSE/WebSocket.
  • Observability: log recall@k on sampled queries to track quality.

Analytics / Events

  • workspace_search {queryLen, topK, filters, hits}
  • workspace_qa {questionLen, citedCount, latencyMs}
  • citation_click {docId, location}
  • KPIs: time-to-first-answer, retention uplift for users who use search/QA, zero-result rate.

Rollout Plan

  1. Phase 1: Indexing + semantic search (web) with filters and citations.
  2. Phase 2: Workspace Q&A + streaming + VS Code extension integration.
  3. Phase 3: Mobile support + admin tools (reindex UI, queue health).

Tasks

Backend (Express)

  • Add /v1/search/semantic, /v1/qa/workspace, /v1/index/* routes + validators.
  • Implement chunking+embeddings service; vector store adapter; Redis caching.
  • Queue workers (RabbitMQ) for indexing; idempotent updates by content hash.
  • Unit/integration tests; load tests for p95 latency.

GraphQL

  • Schema types + resolvers for workspaceSearch and workspaceQA.
  • Auth directives to enforce per-user isolation.

Frontend (React)

  • Global search bar + results list with filters drawer.
  • Update ChatModal: scope toggle + citation rendering + copy/export.
  • Empty/Loading/Skeleton states; a11y + keyboard nav.

VS Code Extension

  • Add “Ask Workspace” view + semantic search command.
  • Reuse existing auth; streaming UI.

Mobile (Expo)

  • Minimal semantic search screen + deep-link to document.
  • Optional: offline cache of last queries.

Infra/CI

  • Feature flag: workspace_search_enabled.
  • Dashboards: queue depth, index lag, query latency, error rate.

Docs

  • Update README.md + openapi.yaml + extension docs.
  • Add “Quality & Evaluation” section (recall@k, groundedness).

Open Questions

  • Preferred default vector backend? (pgvector vs FAISS vs managed)
  • Maximum library size before tiered indexing needed?
  • OCR/table extraction scope now vs. follow-up issue?
  • How should tags be managed (freeform vs predefined) for better filters?

Metadata

Metadata

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededquestionFurther information is requested

Projects

Status
Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions