← Engineering
Completed · Offline2025

DocsRetriever

An authenticated document workspace with vector retrieval and streamed answers.

System architectureAuthenticated Next.js application with separate orchestration and GenAI services
DocsRetriever system architectureThe Next.js frontend authenticates with Keycloak and calls a NestJS API. NestJS stores content and vectors in MongoDB and delegates embeddings and streamed language-model responses to a FastAPI GenAI service using OpenAI.EXPERIENCE + IDENTITYAPPLICATION SERVICESDATA + MODELNext.js UIcontent workspacequestion + SSE clientgenerated API clientNextAuthOIDC sessionBearer access tokenauthenticated hooksKeycloakOpenID Connect · realm rolesRS256 JWT · JWKS cacheJWKS limit: 5 requests/minNestJS controllersJWT guardcontent · sections · usersAI endpointsApplication servicesContentService · AIService30 s session timeout60 s stream timeoutFastAPI GenAI routes/content · /search/embed/search/session/search/stream/{id}MongoDB AtlasMongoose content models1536-d cosine vector index100 candidates · top 10SearchServiceUUID generation sessionsin-memory contextasync token streamOpenAIembeddingsstreaming chat modelLangChain adaptersign inOIDCBearer JWTRS256 / JWKSvalidated DTOHTTP JSONpersist / vector searchcreate generation sessionembed / stream
Verified search sequenceVector retrieval followed by an in-memory generation session and SSE response
  1. Authenticate. NextAuth obtains an OIDC token; NestJS validates its RS256 signature through Keycloak JWKS.
  2. Embed the question. NestJS calls FastAPI /search/embed, which delegates to OpenAI embeddings.
  3. Retrieve context. MongoDB vector search evaluates 100 candidates and returns the top 10 content records.
  4. Create a session. NestJS sends the question and retrieved text/link/table content to FastAPI, which stores it under a UUID in memory.
  5. Stream the answer. The browser connects through authenticated SSE; FastAPI streams model chunks through NestJS to the UI.

Problem

Project brief

Help teams organise internal documents and retrieve relevant passages before generating an answer.

Contribution

Role and scope

Owned product design, application architecture, full-stack development and deployment.

Next.js · NestJS · FastAPI · MongoDB · Keycloak · OpenAI

Implementation

Key technical decisions

  1. Used NestJS as the authenticated application and orchestration boundary, backed by Keycloak and MongoDB.
  2. Separated embeddings and streaming model calls into a FastAPI service using LangChain and OpenAI adapters.
  3. Stored 1536-dimensional vectors with content records and queried a MongoDB cosine index using 100 candidates and a top-10 result limit.

Constraints

Engineering constraints

  • Keep authentication separate from application logic through OpenID Connect and validated RS256 access tokens.
  • Coordinate TypeScript application services with a dedicated Python GenAI runtime.
  • Stream generated answers without holding a long synchronous browser request open.

Outcome

Result

The completed application combined authenticated workspaces, top-10 vector retrieval and SSE answer streaming. The service is now offline.

Completed project · Public service no longer available