{
  "info": {
    "name": "Hindsight API",
    "description": "RAG-powered API with PostgreSQL persistence — upload documents, create chat sessions, and ask questions about your files.\n\n## Setup\n1. Ensure PostgreSQL is running\n2. Set env vars or use defaults: `PGHOST=localhost PGPORT=5432 PGDATABASE=hindsight PGUSER=postgres PGPASSWORD=postgres`\n3. Start the server: `node server.js`\n\n## Postman Variables\nSet `{{base_url}}` to `http://localhost:3000` and `{{user_id}}` to a test user ID.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "http://localhost:3000",
      "type": "string"
    },
    {
      "key": "user_id",
      "value": "user@example.com",
      "type": "string"
    },
    {
      "key": "chat_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "doc_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "file_names",
      "value": "notes.txt,research.md",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "Health",
      "item": [
        {
          "name": "GET /health",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/health",
              "host": ["{{base_url}}"],
              "path": ["health"]
            },
            "description": "Check server status, PostgreSQL connection, and vector store chunk count."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"status\": \"ok\",\n  \"api\": \"standalone\",\n  \"postgres\": \"connected\",\n  \"chunks\": 42\n}"
            }
          ]
        }
      ]
    },
    {
      "name": "Chats",
      "item": [
        {
          "name": "POST /chats — Create chat",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"user_id\": \"{{user_id}}\",\n  \"title\": \"My first chat\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/chats",
              "host": ["{{base_url}}"],
              "path": ["chats"]
            },
            "description": "Create a new chat session. Returns the chat id to use in subsequent requests."
          },
          "event": [
            {
              "listen": "test",
              "script": {
                "exec": [
                  "if (pm.response.code === 201) {",
                  "  var json = pm.response.json();",
                  "  pm.collectionVariables.set('chat_id', json.id.toString());",
                  "}"
                ],
                "type": "text/javascript"
              }
            }
          ],
          "response": [
            {
              "name": "Created",
              "status": "Created",
              "code": 201,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"id\": 1,\n  \"user_id\": \"user@example.com\",\n  \"title\": \"My first chat\",\n  \"created_at\": \"2026-05-12T10:00:00.000Z\",\n  \"updated_at\": \"2026-05-12T10:00:00.000Z\"\n}"
            }
          ]
        },
        {
          "name": "GET /chats — List chats",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/chats?user_id={{user_id}}",
              "host": ["{{base_url}}"],
              "path": ["chats"],
              "query": [
                { "key": "user_id", "value": "{{user_id}}" }
              ]
            },
            "description": "List all chat sessions for a user, ordered by most recently updated."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "[\n  {\n    \"id\": 1,\n    \"user_id\": \"user@example.com\",\n    \"title\": \"My first chat\",\n    \"created_at\": \"2026-05-12T10:00:00.000Z\",\n    \"updated_at\": \"2026-05-12T10:15:00.000Z\"\n  }\n]"
            }
          ]
        },
        {
          "name": "GET /chats/:id — Get chat",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/chats/{{chat_id}}",
              "host": ["{{base_url}}"],
              "path": ["chats", "{{chat_id}}"]
            },
            "description": "Get a single chat session by ID."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"id\": 1,\n  \"user_id\": \"user@example.com\",\n  \"title\": \"My first chat\",\n  \"created_at\": \"2026-05-12T10:00:00.000Z\",\n  \"updated_at\": \"2026-05-12T10:15:00.000Z\"\n}"
            }
          ]
        },
        {
          "name": "PUT /chats/:id — Rename chat",
          "request": {
            "method": "PUT",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"title\": \"Renamed chat title\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/chats/{{chat_id}}",
              "host": ["{{base_url}}"],
              "path": ["chats", "{{chat_id}}"]
            },
            "description": "Rename an existing chat session."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"id\": 1,\n  \"user_id\": \"user@example.com\",\n  \"title\": \"Renamed chat title\",\n  \"created_at\": \"2026-05-12T10:00:00.000Z\",\n  \"updated_at\": \"2026-05-12T10:20:00.000Z\"\n}"
            }
          ]
        },
        {
          "name": "DELETE /chats/:id — Delete chat",
          "request": {
            "method": "DELETE",
            "header": [],
            "url": {
              "raw": "{{base_url}}/chats/{{chat_id}}",
              "host": ["{{base_url}}"],
              "path": ["chats", "{{chat_id}}"]
            },
            "description": "Delete a chat and all its messages (cascading delete)."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"message\": \"Chat deleted\",\n  \"id\": 1\n}"
            }
          ]
        },
        {
          "name": "GET /chats/:id/messages — Get messages",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/chats/{{chat_id}}/messages",
              "host": ["{{base_url}}"],
              "path": ["chats", "{{chat_id}}", "messages"]
            },
            "description": "Get all messages in a chat session, ordered oldest first."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "[\n  {\n    \"id\": 1,\n    \"chat_id\": 1,\n    \"role\": \"user\",\n    \"content\": \"What is in my documents?\",\n    \"created_at\": \"2026-05-12T10:10:00.000Z\"\n  },\n  {\n    \"id\": 2,\n    \"chat_id\": 1,\n    \"role\": \"assistant\",\n    \"content\": \"Based on your documents, ...\",\n    \"created_at\": \"2026-05-12T10:10:05.000Z\"\n  }\n]"
            }
          ]
        }
      ]
    },
    {
      "name": "Documents",
      "item": [
        {
          "name": "POST /upload-drive — Upload files (JSON)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"onedrive_id\": \"{{user_id}}\",\n  \"files\": [\n    {\n      \"file_name\": \"notes.txt\",\n      \"content\": \"Meeting notes from 2026:\\n- Discussed Q3 roadmap\\n- Budget approved for new initiative\\n- Action items assigned to team leads\"\n    },\n    {\n      \"file_name\": \"research.md\",\n      \"content\": \"# Research Notes\\n\\nKey findings from the latest analysis:\\n1. User engagement increased by 35%\\n2. New feature adoption rate is 68%\\n3. Customer satisfaction score improved to 4.5/5\"\n    }\n  ]\n}"
            },
            "url": {
              "raw": "{{base_url}}/upload-drive",
              "host": ["{{base_url}}"],
              "path": ["upload-drive"]
            },
            "description": "Upload multiple documents as JSON. Each file needs a `file_name` and `content` string. Files are indexed into the vector store AND saved to PostgreSQL."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"message\": \"Indexing complete\",\n  \"onedrive_id\": \"user@example.com\",\n  \"bank_id\": \"user-user@example.com\",\n  \"total_received\": 2,\n  \"indexed\": 2,\n  \"skipped\": 0,\n  \"failed_files\": []\n}"
            }
          ]
        },
        {
          "name": "POST /test-upload — Upload file (multipart)",
          "request": {
            "method": "POST",
            "header": [],
            "body": {
              "mode": "formdata",
              "formdata": [
                {
                  "key": "user_id",
                  "value": "{{user_id}}",
                  "type": "text"
                },
                {
                  "key": "file",
                  "type": "file",
                  "src": "",
                  "description": "Attach a .txt, .docx, or .pdf file"
                }
              ]
            },
            "url": {
              "raw": "{{base_url}}/test-upload",
              "host": ["{{base_url}}"],
              "path": ["test-upload"]
            },
            "description": "Upload a single file via multipart/form-data (for testing or manual upload). Supports .txt, .docx, .pdf."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"message\": \"File uploaded and indexed!\",\n  \"file_name\": \"notes.txt\",\n  \"user_id\": \"user@example.com\",\n  \"characters_extracted\": 142,\n  \"indexing_result\": {\n    \"message\": \"Indexing complete\",\n    \"indexed\": 1,\n    \"skipped\": 0\n  }\n}"
            }
          ]
        },
        {
          "name": "GET /documents — List documents",
          "request": {
            "method": "GET",
            "header": [],
            "url": {
              "raw": "{{base_url}}/documents?user_id={{user_id}}",
              "host": ["{{base_url}}"],
              "path": ["documents"],
              "query": [
                { "key": "user_id", "value": "{{user_id}}" }
              ]
            },
            "description": "List all indexed documents for a user (metadata only, not full content)."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "[\n  {\n    \"id\": 1,\n    \"user_id\": \"user@example.com\",\n    \"file_name\": \"notes.txt\",\n    \"created_at\": \"2026-05-12T10:00:00.000Z\"\n  },\n  {\n    \"id\": 2,\n    \"user_id\": \"user@example.com\",\n    \"file_name\": \"research.md\",\n    \"created_at\": \"2026-05-12T10:00:01.000Z\"\n  }\n]"
            }
          ]
        }
      ]
    },
    {
      "name": "Q&A",
      "item": [
        {
          "name": "POST /ask-latest — Ask about latest document",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"onedrive_id\": \"{{user_id}}\",\n  \"chat_id\": {{chat_id}},\n  \"question\": \"What is this document about?\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/ask-latest",
              "host": ["{{base_url}}"],
              "path": ["ask-latest"]
            },
            "description": "Ask a question about the MOST RECENTLY uploaded document. No `document_ids` needed — automatically finds the latest document for this user.\n\n**Important:** First create a chat via `POST /chats`, then use its `id` as `chat_id`."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"onedrive_id\": \"user@example.com\",\n  \"bank_id\": \"user-user@example.com\",\n  \"chat_id\": 1,\n  \"question\": \"What is this document about?\",\n  \"document_ids\": [5],\n  \"document_name\": \"my-notes.txt\",\n  \"answer\": \"This document contains notes about...\",\n  \"facts_used\": [...]\n}"
            }
          ]
        },
        {
          "name": "POST /ask-question — Ask (all documents)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"onedrive_id\": \"{{user_id}}\",\n  \"chat_id\": {{chat_id}},\n  \"question\": \"What were the key findings from the research?\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/ask-question",
              "host": ["{{base_url}}"],
              "path": ["ask-question"]
            },
            "description": "Ask a question across ALL your indexed documents. Omit the `documents` field to search everything.\n\n**Important:** First create a chat via `POST /chats`, then use its `id` as `chat_id`."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"onedrive_id\": \"user@example.com\",\n  \"bank_id\": \"user-user@example.com\",\n  \"chat_id\": 1,\n  \"question\": \"What were the key findings from the research?\",\n  \"answer\": \"Based on your documents, user engagement increased by 35%, new feature adoption rate is 68%, and customer satisfaction score improved to 4.5/5.\",\n  \"facts_used\": [\n    \"# Research Notes\\n\\nKey findings from the latest analysis:\\n1. User engagement increased by 35%\\n2. New feature adoption rate is 68%\\n3. Customer satisfaction score improved to 4.5/5\"\n  ]\n}"
            }
          ]
        },
        {
          "name": "POST /ask-question — Ask (specific document_ids)",
          "request": {
            "method": "POST",
            "header": [
              { "key": "Content-Type", "value": "application/json" }
            ],
            "body": {
              "mode": "raw",
              "raw": "{\n  \"onedrive_id\": \"{{user_id}}\",\n  \"chat_id\": {{chat_id}},\n  \"document_ids\": [1, 2],\n  \"question\": \"What were the key findings from the research?\"\n}"
            },
            "url": {
              "raw": "{{base_url}}/ask-question",
              "host": ["{{base_url}}"],
              "path": ["ask-question"]
            },
            "description": "Ask a question scoped to SPECIFIC documents only. Pass `document_ids` as an array of integers — these are the `id` values from `GET /documents?user_id=X`.\n\n**Important:** First create a chat via `POST /chats`, then use its `id` as `chat_id`."
          },
          "response": [
            {
              "name": "Success",
              "status": "OK",
              "code": 200,
              "header": [
                { "key": "Content-Type", "value": "application/json" }
              ],
              "body": "{\n  \"onedrive_id\": \"user@example.com\",\n  \"bank_id\": \"user-user@example.com\",\n  \"chat_id\": 1,\n  \"question\": \"What were the key findings from the research?\",\n  \"document_ids\": [1, 2],\n  \"answer\": \"Based on your documents, user engagement increased by 35%, new feature adoption rate is 68%, and customer satisfaction score improved to 4.5/5.\",\n  \"facts_used\": [\n    \"# Research Notes\\n\\nKey findings from the latest analysis:\\n1. User engagement increased by 35%\\n2. New feature adoption rate is 68%\\n3. Customer satisfaction score improved to 4.5/5\"\n  ]\n}"
            }
          ]
        }
      ]
    }
  ]
}
