openapi: 3.0.3 info: title: AI Textbook RAG API description: API for the AI-Native Physical AI & Humanoid Robotics Textbook with RAG functionality version: 1.0.0 servers: - url: http://localhost:8000 description: Development server - url: https://your-deployed-backend.com description: Production server paths: /api/v1/textbook/chapters: get: summary: List all textbook chapters description: Retrieve a list of all available textbook chapters responses: '200': description: List of textbook chapters content: application/json: schema: type: array items: $ref: '#/components/schemas/Chapter' '500': description: Internal server error /api/v1/textbook/chapters/{slug}: get: summary: Get a specific textbook chapter description: Retrieve the content of a specific textbook chapter by its slug parameters: - name: slug in: path required: true description: URL-friendly identifier for the chapter schema: type: string responses: '200': description: Textbook chapter content content: application/json: schema: $ref: '#/components/schemas/ChapterWithContent' '404': description: Chapter not found '500': description: Internal server error /api/v1/textbook/chapters/{slug}/sections: get: summary: Get sections of a chapter description: Retrieve all sections within a specific textbook chapter parameters: - name: slug in: path required: true description: URL-friendly identifier for the chapter schema: type: string responses: '200': description: List of sections in the chapter content: application/json: schema: type: array items: $ref: '#/components/schemas/Section' '404': description: Chapter not found '500': description: Internal server error /api/v1/textbook/search: get: summary: Search textbook content description: Search through textbook content using a query string parameters: - name: q in: query required: true description: Search query schema: type: string - name: limit in: query required: false description: Maximum number of results to return schema: type: integer default: 10 responses: '200': description: Search results content: application/json: schema: type: array items: $ref: '#/components/schemas/SearchResult' '400': description: Invalid search query '500': description: Internal server error /api/v1/rag/query: post: summary: Submit a query to the RAG system description: Submit a technical question to the RAG system and get a response based on textbook content requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UserQueryRequest' responses: '200': description: Response from the RAG system content: application/json: schema: $ref: '#/components/schemas/AIResponse' '400': description: Invalid query format '500': description: Internal server error /api/v1/rag/query-with-selection: post: summary: Submit a query with text selection description: Submit a query about specific selected text from the textbook requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/UserQueryWithSelectionRequest' responses: '200': description: Response from the RAG system content: application/json: schema: $ref: '#/components/schemas/AIResponse' '400': description: Invalid query format '500': description: Internal server error /api/v1/rag/history/{session_id}: get: summary: Get conversation history description: Retrieve the conversation history for a specific session parameters: - name: session_id in: path required: true description: Session identifier schema: type: string responses: '200': description: Conversation history content: application/json: schema: type: array items: $ref: '#/components/schemas/ConversationItem' '404': description: Session not found '500': description: Internal server error /api/v1/auth/login: post: summary: User login description: Authenticate a user and return a session token requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/LoginRequest' responses: '200': description: Login successful content: application/json: schema: $ref: '#/components/schemas/LoginResponse' '401': description: Invalid credentials '500': description: Internal server error /api/v1/auth/register: post: summary: User registration description: Register a new user account requestBody: required: true content: application/json: schema: $ref: '#/components/schemas/RegisterRequest' responses: '201': description: User registered successfully content: application/json: schema: $ref: '#/components/schemas/RegisterResponse' '400': description: Invalid registration data '409': description: User already exists '500': description: Internal server error /api/v1/auth/me: get: summary: Get current user info description: Retrieve information about the currently authenticated user security: - BearerAuth: [] responses: '200': description: Current user information content: application/json: schema: $ref: '#/components/schemas/User' '401': description: Unauthorized '500': description: Internal server error /health: get: summary: Health check description: Check if the API is running and healthy responses: '200': description: API is healthy content: application/json: schema: type: object properties: status: type: string example: "healthy" timestamp: type: string format: date-time components: schemas: Chapter: type: object required: - id - title - slug - order - created_at - updated_at properties: id: type: string format: uuid description: Unique identifier for the chapter title: type: string description: Title of the chapter slug: type: string description: URL-friendly identifier for the chapter order: type: integer description: Order position in the textbook sequence created_at: type: string format: date-time description: Creation timestamp updated_at: type: string format: date-time description: Last update timestamp ChapterWithContent: allOf: - $ref: '#/components/schemas/Chapter' - type: object properties: content: type: string description: The full content of the chapter in Markdown format metadata: type: object description: Additional metadata including tags, difficulty level, prerequisites sections: type: array items: $ref: '#/components/schemas/Section' Section: type: object required: - id - title - level - order - created_at properties: id: type: string format: uuid description: Unique identifier for the section title: type: string description: Title of the section level: type: integer description: Hierarchy level (1 for main sections, 2 for subsections, etc.) order: type: integer description: Order position within the chapter created_at: type: string format: date-time description: Creation timestamp SearchResult: type: object required: - id - title - content_snippet - url - score properties: id: type: string format: uuid description: Unique identifier for the search result title: type: string description: Title of the matching content content_snippet: type: string description: Snippet of the matching content url: type: string description: URL to the full content score: type: number format: float description: Relevance score for the search result UserQueryRequest: type: object required: - query - session_id properties: query: type: string description: The user's query/question maxLength: 2000 session_id: type: string description: Session identifier for tracking conversation history context: type: string description: Optional context to provide with the query UserQueryWithSelectionRequest: allOf: - $ref: '#/components/schemas/UserQueryRequest' - type: object required: - selected_text properties: selected_text: type: string description: The text that the user has selected to ask about AIResponse: type: object required: - id - response_text - confidence_score - source_chunks - generated_at properties: id: type: string format: uuid description: Unique identifier for the response response_text: type: string description: The generated response text confidence_score: type: number format: float minimum: 0.0 maximum: 1.0 description: Confidence score for the response source_chunks: type: array items: type: string format: uuid description: List of chunk IDs used to generate the response generated_at: type: string format: date-time description: Timestamp of response generation token_usage: type: object properties: input_tokens: type: integer output_tokens: type: integer total_tokens: type: integer ConversationItem: type: object required: - id - type - content - timestamp properties: id: type: string format: uuid description: Unique identifier for the conversation item type: type: string enum: [query, response] description: Type of the conversation item content: type: string description: Content of the query or response timestamp: type: string format: date-time description: Timestamp of the conversation item LoginRequest: type: object required: - email - password properties: email: type: string format: email description: User's email address password: type: string description: User's password LoginResponse: type: object required: - access_token - token_type - user properties: access_token: type: string description: JWT access token token_type: type: string description: Type of the token (usually "bearer") user: $ref: '#/components/schemas/User' RegisterRequest: type: object required: - email - password - full_name properties: email: type: string format: email description: User's email address password: type: string description: User's password (minimum 8 characters) minLength: 8 full_name: type: string description: User's full name RegisterResponse: type: object required: - message - user properties: message: type: string description: Confirmation message user: $ref: '#/components/schemas/User' User: type: object required: - id - email - full_name - created_at properties: id: type: string format: uuid description: Unique identifier for the user email: type: string format: email description: User's email address full_name: type: string description: User's full name created_at: type: string format: date-time description: Account creation timestamp securitySchemes: BearerAuth: type: http scheme: bearer bearerFormat: JWT security: - BearerAuth: []