Fig. 04 · Document intelligence / Graph RAG
Cogni
Graph
Documents become a graph you can explore, then question.
§ 01
The problem
Search works when you know what you are looking for. It is much weaker at the harder question: how do the people, events and claims across a pile of documents connect?
CogniGraph answers from the documents instead of from model memory, and puts the extracted graph on screen, so the context behind an answer can be inspected rather than taken on trust.
§ 02
System drawing
Solid = per request · Dashed = prepared separately
- 01 · BrowserAsk a questionchat or split view
- 02 · Next.js APIResolve the userClerk session → that user’s documents only
- 03 · OpenAIEmbed the querytext-embedding-3-small
- 04 · PostgresPassages + relationshipspgvector similarity and graph lookups
- 05 · OutStreamed answerAI SDK
§ 03
How it came together
Scroll to step through · Mine = my work
Documents get in
Files upload directly to S3, and a worker extracts their text, with OCR for images.
+ presigned S3 upload+ FastAPI worker: extract text / OCR- q3-report.pdffinancialprocessing
- supplier-contract.pdflegalcompleted
- meeting-notes.txtgeneralcompleted
Text becomes vectors
Each document is chunked by its domain mode, embedded, and stored in Postgres with pgvector.
+ domain-aware chunk size and overlap+ embeddings → pgvectorS3extractchunkembedPostgresText becomes a graph
Entities and the relationships between them are extracted per document and drawn as a graph you can filter and inspect.
+ entity + relationship extraction → nodes, edges+ force-directed graph viewSupplierContractRenewal dateAnswers grounded in both
Chat retrieves passages and relationships together and streams the reply.
- passages only+ passages + graph relationships+ streamed repliesWhich contracts renew before the Q3 report is due?
Two are linked to a renewal date in that window…
§ 04
Decision log
- D-01
Upload straight to storage
The browser sends a file to S3 through a presigned URL that expires after 60 seconds, so documents never pass through the web server. storage.ts ↗
- D-02
Process outside the request
A FastAPI worker runs extraction as a background task and records each document as processing, completed or failed, so a slow file never holds a page open. main.py ↗
- D-03
Chunk by domain
Nine document modes, from legal to engineering, each set their own chunk size (800 to 2,500 characters) and overlap, and steer what the graph extraction looks for. main.py ↗
- D-04
Retrieve from the vectors and the graph
A question pulls the closest passages by embedding similarity and the relationships whose entities match it, both limited to the signed-in user’s documents. route.ts ↗
§ 05
What I built
- Document processing workerpython_service/main.py ↗
- Retrieval & streaming chatsrc/app/api/chat/route.ts ↗
- Presigned uploadssrc/actions/storage.ts ↗
- Interactive graph viewsrc/components/GraphVisualization.tsx ↗
