> ## Documentation Index
> Fetch the complete documentation index at: https://docs.trieve.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Get RAG Analytics

> This route allows you to view the RAG analytics for a dataset.



## OpenAPI

````yaml post /api/analytics/rag
openapi: 3.0.3
info:
  title: Trieve API
  description: >-
    Trieve OpenAPI Specification. This document describes all of the operations
    available through the Trieve API.
  contact:
    name: Trieve Team
    url: https://trieve.ai
    email: developers@trieve.ai
  license:
    name: BSL
    url: https://github.com/devflowinc/trieve/blob/main/LICENSE.txt
  version: 0.13.0
servers:
  - url: https://api.trieve.ai
    description: Production server
  - url: http://localhost:8090
    description: Local development server
security: []
tags:
  - name: Invitation
    description: Invitation endpoint. Exists to invite users to an organization.
  - name: Auth
    description: Authentication endpoint. Serves to register and authenticate users.
  - name: User
    description: User endpoint. Enables you to modify user roles and information.
  - name: Organization
    description: >-
      Organization endpoint. Enables you to modify organization roles and
      information.
  - name: Dataset
    description: >-
      Dataset endpoint. Datasets belong to organizations and hold configuration
      information for both client and server. Datasets contain chunks and chunk
      groups.
  - name: Chunk
    description: >-
      Chunk endpoint. Think of chunks as individual searchable units of
      information. The majority of your integration will likely be with the
      Chunk endpoint.
  - name: Chunk Group
    description: >-
      Chunk groups endpoint. Think of a chunk_group as a bookmark folder within
      the dataset.
  - name: Crawl
    description: Crawl endpoint. Used to create and manage crawls for datasets.
  - name: File
    description: >-
      File endpoint. When files are uploaded, they are stored in S3 and broken
      up into chunks with text extraction from Apache Tika. You can upload files
      of pretty much any type up to 1GB in size. See chunking algorithm details
      at `docs.trieve.ai` for more information on how chunking works. Improved
      default chunking is on our roadmap.
  - name: Events
    description: >-
      Notifications endpoint. Files are uploaded asynchronously and events are
      sent to the user when the upload is complete.
  - name: Topic
    description: >-
      Topic chat endpoint. Think of topics as the storage system for gen-ai chat
      memory. Gen AI messages belong to topics.
  - name: Message
    description: >-
      Message chat endpoint. Messages are units belonging to a topic in the
      context of a chat with a LLM. There are system, user, and assistant
      messages.
  - name: Stripe
    description: >-
      Stripe endpoint. Used for the managed SaaS version of this app. Eventually
      this will become a micro-service. Reach out to the team using contact info
      found at `docs.trieve.ai` for more information.
  - name: Health
    description: Health check endpoint. Used to check if the server is up and running.
  - name: Metrics
    description: Metrics endpoint. Used to get information for monitoring
  - name: Analytics
    description: Analytics endpoint. Used to get information for search and RAG analytics
  - name: Experiment
    description: Experiment endpoint. Used to create and manage experiments
paths:
  /api/analytics/rag:
    post:
      tags:
        - Analytics
      summary: Get RAG Analytics
      description: This route allows you to view the RAG analytics for a dataset.
      operationId: get_rag_analytics
      parameters:
        - name: TR-Dataset
          in: header
          description: >-
            The dataset id or tracking_id to use for the request. We assume you
            intend to use an id if the value is a valid uuid.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        description: JSON request payload to filter the graph
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RAGAnalytics'
        required: true
      responses:
        '200':
          description: The RAG analytics for the dataset
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RAGAnalyticsResponse'
        '400':
          description: Service error relating to getting RAG analytics
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponseBody'
      security:
        - ApiKey:
            - admin
components:
  schemas:
    RAGAnalytics:
      oneOf:
        - type: object
          title: RAGQueries
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            has_clicks:
              type: boolean
              nullable: true
            page:
              type: integer
              format: int32
              nullable: true
              minimum: 0
            sort_by:
              allOf:
                - $ref: '#/components/schemas/RAGSortBy'
              nullable: true
            sort_order:
              allOf:
                - $ref: '#/components/schemas/SortOrder'
              nullable: true
            type:
              type: string
              enum:
                - rag_queries
        - type: object
          title: RAGUsage
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            type:
              type: string
              enum:
                - rag_usage
        - type: object
          title: RAGUsageGraph
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - rag_usage_graph
        - type: object
          title: QueryDetails
          required:
            - request_id
            - type
          properties:
            request_id:
              type: string
              format: uuid
            type:
              type: string
              enum:
                - rag_query_details
        - type: object
          title: RAGQueryRatings
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            type:
              type: string
              enum:
                - rag_query_ratings
        - type: object
          title: FollowupQueries
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            page:
              type: integer
              format: int32
              nullable: true
              minimum: 0
            type:
              type: string
              enum:
                - followup_queries
        - type: object
          title: TopicAnalytics
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/TopicAnalyticsFilter'
              nullable: true
            page:
              type: integer
              format: int32
              nullable: true
              minimum: 0
            sort_by:
              allOf:
                - $ref: '#/components/schemas/RAGSortBy'
              nullable: true
            sort_order:
              allOf:
                - $ref: '#/components/schemas/SortOrder'
              nullable: true
            topic_events_filter:
              allOf:
                - $ref: '#/components/schemas/TopicEventFilter'
              nullable: true
            type:
              type: string
              enum:
                - topic_queries
        - type: object
          title: TopicDetails
          required:
            - topic_id
            - type
          properties:
            topic_id:
              type: string
              format: uuid
            type:
              type: string
              enum:
                - topic_details
        - type: object
          title: TopicsOverTime
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/TopicAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - topics_over_time
        - type: object
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - ctr_metrics_over_time
        - type: object
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - messages_per_user
        - type: object
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/RAGAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - chat_average_rating
        - type: object
          title: ChatConversionRate
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/TopicAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - chat_conversion_rate
        - type: object
          title: EventFunnel
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/TopicAnalyticsFilter'
              nullable: true
            type:
              type: string
              enum:
                - event_funnel
        - type: object
          title: EventsForTopic
          required:
            - topic_id
            - type
          properties:
            topic_id:
              type: string
              format: uuid
            type:
              type: string
              enum:
                - events_for_topic
        - type: object
          title: ChatRevenue
          required:
            - type
          properties:
            direct:
              type: boolean
              nullable: true
            filter:
              allOf:
                - $ref: '#/components/schemas/EventAnalyticsFilter'
              nullable: true
            granularity:
              allOf:
                - $ref: '#/components/schemas/Granularity'
              nullable: true
            type:
              type: string
              enum:
                - chat_revenue
        - type: object
          title: PopularChats
          required:
            - type
          properties:
            filter:
              allOf:
                - $ref: '#/components/schemas/TopicAnalyticsFilter'
              nullable: true
            page:
              type: integer
              format: int32
              nullable: true
              minimum: 0
            type:
              type: string
              enum:
                - popular_chats
      discriminator:
        propertyName: type
    RAGAnalyticsResponse:
      oneOf:
        - $ref: '#/components/schemas/RagQueryResponse'
        - $ref: '#/components/schemas/RAGUsageResponse'
        - $ref: '#/components/schemas/RAGUsageGraphResponse'
        - $ref: '#/components/schemas/RagQueryEvent'
        - $ref: '#/components/schemas/RagQueryRatingsResponse'
        - $ref: '#/components/schemas/FollowupQueriesResponse'
        - $ref: '#/components/schemas/TopicQueriesResponse'
        - $ref: '#/components/schemas/TopicDetailsResponse'
        - $ref: '#/components/schemas/TopicsOverTimeResponse'
        - $ref: '#/components/schemas/CTRMetricsOverTimeResponse'
        - $ref: '#/components/schemas/MessagesPerUserResponse'
        - $ref: '#/components/schemas/ChatAverageRatingResponse'
        - $ref: '#/components/schemas/ChatConversionRateResponse'
        - $ref: '#/components/schemas/EventNameAndCountsResponse'
        - $ref: '#/components/schemas/EventsForTopicResponse'
        - $ref: '#/components/schemas/ChatRevenueResponse'
        - $ref: '#/components/schemas/PopularChatsResponse'
    ErrorResponseBody:
      type: object
      required:
        - message
      properties:
        message:
          type: string
      example:
        message: Bad Request
    RAGAnalyticsFilter:
      type: object
      properties:
        component_name:
          type: string
          nullable: true
        date_range:
          allOf:
            - $ref: '#/components/schemas/DateRange'
          nullable: true
        query:
          type: string
          nullable: true
        query_rating:
          allOf:
            - $ref: '#/components/schemas/QueryRatingRange'
          nullable: true
        rag_type:
          allOf:
            - $ref: '#/components/schemas/RagTypes'
          nullable: true
    RAGSortBy:
      type: string
      enum:
        - hallucination_score
        - top_score
        - created_at
    SortOrder:
      type: string
      enum:
        - desc
        - asc
    Granularity:
      type: string
      enum:
        - minute
        - second
        - hour
        - day
        - month
    TopicAnalyticsFilter:
      type: object
      properties:
        component_name:
          type: string
          nullable: true
        date_range:
          allOf:
            - $ref: '#/components/schemas/DateRange'
          nullable: true
        hallucination_score:
          allOf:
            - $ref: '#/components/schemas/FloatRange'
          nullable: true
        query:
          type: string
          nullable: true
        query_rating:
          allOf:
            - $ref: '#/components/schemas/QueryRatingRange'
          nullable: true
        rag_type:
          allOf:
            - $ref: '#/components/schemas/RagTypes'
          nullable: true
        top_score:
          allOf:
            - $ref: '#/components/schemas/FloatRange'
          nullable: true
    TopicEventFilter:
      type: object
      required:
        - event_names
        - inverted
      properties:
        event_names:
          type: array
          items:
            $ref: '#/components/schemas/EventNamesFilter'
          description: Filter by event type
        inverted:
          type: boolean
    EventAnalyticsFilter:
      type: object
      description: Filter to apply to the events when querying for them
      properties:
        date_range:
          allOf:
            - $ref: '#/components/schemas/DateRange'
          nullable: true
        event_type:
          allOf:
            - $ref: '#/components/schemas/EventTypesFilter'
          nullable: true
        is_conversion:
          type: boolean
          description: Filter by conversions
          nullable: true
        metadata_filter:
          type: string
          description: Filter by metadata path i.e. path.attribute = \"value\"
          nullable: true
        user_id:
          type: string
          description: Filter by user ID
          nullable: true
      example:
        date_range:
          gt: '2021-08-10T00:00:00Z'
          lt: '2021-08-11T00:00:00Z'
        event_type: view
        is_conversion: true
        metadata_filter: path = "value"
        user_id: user1
    RagQueryResponse:
      type: object
      title: RagQueryResponse
      required:
        - queries
      properties:
        queries:
          type: array
          items:
            $ref: '#/components/schemas/RagQueryEvent'
    RAGUsageResponse:
      type: object
      title: RAGUsageResponse
      required:
        - total_queries
      properties:
        total_queries:
          type: integer
          format: int32
          minimum: 0
    RAGUsageGraphResponse:
      type: object
      title: RAGUsageGraphResponse
      required:
        - points
      properties:
        points:
          type: array
          items:
            $ref: '#/components/schemas/IntegerTimePoint'
    RagQueryEvent:
      type: object
      title: RagQueryEvent
      required:
        - id
        - rag_type
        - user_message
        - search_id
        - topic_id
        - results
        - dataset_id
        - llm_response
        - top_score
        - hallucination_score
        - detected_hallucinations
        - created_at
        - user_id
      properties:
        created_at:
          type: string
        dataset_id:
          type: string
          format: uuid
        detected_hallucinations:
          type: array
          items:
            type: string
        hallucination_score:
          type: number
          format: double
        id:
          type: string
          format: uuid
        llm_response:
          type: string
        metadata:
          nullable: true
        query_rating:
          allOf:
            - $ref: '#/components/schemas/SearchQueryRating'
          nullable: true
        rag_type:
          $ref: '#/components/schemas/ClickhouseRagTypes'
        results:
          type: array
          items: {}
        search_id:
          type: string
          format: uuid
        top_score:
          type: number
          format: float
        topic_id:
          type: string
          format: uuid
        user_id:
          type: string
        user_message:
          type: string
    RagQueryRatingsResponse:
      type: object
      title: RagQueryRatingsResponse
      required:
        - total_positive_ratings
        - total_negative_ratings
      properties:
        total_negative_ratings:
          type: integer
          format: int64
          description: Total number of negative RAG ratings
        total_positive_ratings:
          type: integer
          format: int64
          description: Total number of positive RAG ratings
    FollowupQueriesResponse:
      type: object
      required:
        - top_queries
      properties:
        top_queries:
          type: array
          items:
            $ref: '#/components/schemas/FollowupQuery'
    TopicQueriesResponse:
      type: object
      required:
        - topics
      properties:
        topics:
          type: array
          items:
            $ref: '#/components/schemas/ClickhouseTopicAnalyticsSummary'
    TopicDetailsResponse:
      type: object
      required:
        - topic
        - messages
      properties:
        messages:
          type: array
          items:
            $ref: '#/components/schemas/RagQueryEvent'
        topic:
          $ref: '#/components/schemas/TopicQuery'
    TopicsOverTimeResponse:
      type: object
      required:
        - total_topics
        - points
      properties:
        points:
          type: array
          items:
            $ref: '#/components/schemas/IntegerTimePoint'
        total_topics:
          type: integer
          format: int64
    CTRMetricsOverTimeResponse:
      type: object
      required:
        - total_ctr
        - points
      properties:
        points:
          type: array
          items:
            $ref: '#/components/schemas/FloatTimePoint'
        total_ctr:
          type: number
          format: double
    MessagesPerUserResponse:
      type: object
      required:
        - avg_messages_per_user
        - points
      properties:
        avg_messages_per_user:
          type: number
          format: double
        points:
          type: array
          items:
            $ref: '#/components/schemas/FloatTimePoint'
    ChatAverageRatingResponse:
      type: object
      required:
        - avg_chat_rating
        - points
      properties:
        avg_chat_rating:
          type: number
          format: double
        points:
          type: array
          items:
            $ref: '#/components/schemas/FloatTimePoint'
    ChatConversionRateResponse:
      type: object
      required:
        - conversion_rate
        - points
      properties:
        conversion_rate:
          type: number
          format: double
        points:
          type: array
          items:
            $ref: '#/components/schemas/FloatTimePoint'
    EventNameAndCountsResponse:
      type: object
      required:
        - event_names
      properties:
        event_names:
          type: array
          items:
            $ref: '#/components/schemas/EventNameAndCounts'
    EventsForTopicResponse:
      type: object
      required:
        - events
      properties:
        events:
          type: array
          items:
            $ref: '#/components/schemas/EventData'
    ChatRevenueResponse:
      type: object
      required:
        - revenue
        - points
      properties:
        points:
          type: array
          items:
            $ref: '#/components/schemas/FloatTimePoint'
        revenue:
          type: number
          format: double
    PopularChatsResponse:
      type: object
      required:
        - chats
      properties:
        chats:
          type: array
          items:
            $ref: '#/components/schemas/PopularChat'
    DateRange:
      type: object
      description: >-
        DateRange is a JSON object which can be used to filter chunks by a range
        of dates. This leverages the time_stamp field on chunks in your dataset.
        You can specify this if you want values in a certain range. You must
        provide ISO 8601 combined date and time without timezone.
      properties:
        gt:
          type: string
          nullable: true
        gte:
          type: string
          nullable: true
        lt:
          type: string
          nullable: true
        lte:
          type: string
          nullable: true
      example:
        gt: '2021-01-01 00:00:00.000'
        gte: '2021-01-01 00:00:00.000'
        lt: '2021-01-01 00:00:00.000'
        lte: '2021-01-01 00:00:00.000'
    QueryRatingRange:
      type: object
      properties:
        gt:
          type: integer
          format: int32
          nullable: true
          minimum: 0
        gte:
          type: integer
          format: int32
          nullable: true
          minimum: 0
        lt:
          type: integer
          format: int32
          nullable: true
          minimum: 0
        lte:
          type: integer
          format: int32
          nullable: true
          minimum: 0
      example:
        gt: 1
        gte: 1
        lt: 1
        lte: 1
    RagTypes:
      type: string
      enum:
        - chosen_chunks
        - all_chunks
    FloatRange:
      type: object
      properties:
        gt:
          type: number
          format: double
          nullable: true
        gte:
          type: number
          format: double
          nullable: true
        lt:
          type: number
          format: double
          nullable: true
        lte:
          type: number
          format: double
          nullable: true
    EventNamesFilter:
      type: string
      enum:
        - component_close
        - component_open
        - View
        - site-followup_query
        - Click
        - site-add_to_cart
        - site-checkout_end
    EventTypesFilter:
      type: string
      enum:
        - view
        - filter_clicked
        - click
        - add_to_cart
        - purchase
    IntegerTimePoint:
      type: object
      required:
        - time_stamp
        - point
      properties:
        point:
          type: integer
          format: int64
        time_stamp:
          type: string
    SearchQueryRating:
      type: object
      required:
        - rating
      properties:
        metadata:
          nullable: true
        note:
          type: string
          nullable: true
        rating:
          type: integer
          format: int32
    ClickhouseRagTypes:
      type: string
      enum:
        - chosen_chunks
        - all_chunks
    FollowupQuery:
      type: object
      required:
        - query
        - count
      properties:
        count:
          type: integer
          format: int64
        query:
          type: string
    ClickhouseTopicAnalyticsSummary:
      type: object
      required:
        - id
        - name
        - topic_id
        - owner_id
        - created_at
        - updated_at
        - message_count
        - avg_top_score
        - avg_hallucination_score
        - event_names
      properties:
        avg_hallucination_score:
          type: number
          format: double
        avg_query_rating:
          type: number
          format: double
          nullable: true
        avg_top_score:
          type: number
          format: double
        created_at:
          type: string
        event_names:
          type: array
          items:
            type: string
          description: >-
            All event_names that are  associated with the topic, may contain
            duplicate names
        id:
          type: string
          format: uuid
        message_count:
          type: integer
          format: int64
          minimum: 0
        name:
          type: string
        owner_id:
          type: string
        topic_id:
          type: string
          format: uuid
        updated_at:
          type: string
    TopicQuery:
      type: object
      required:
        - id
        - name
        - topic_id
        - dataset_id
        - owner_id
        - created_at
        - updated_at
      properties:
        created_at:
          type: string
        dataset_id:
          type: string
          format: uuid
        id:
          type: string
          format: uuid
        metadata:
          nullable: true
        name:
          type: string
        owner_id:
          type: string
        topic_id:
          type: string
          format: uuid
        updated_at:
          type: string
    FloatTimePoint:
      type: object
      required:
        - time_stamp
        - point
      properties:
        point:
          type: number
          format: double
        time_stamp:
          type: string
    EventNameAndCounts:
      type: object
      required:
        - event_name
        - event_count
      properties:
        event_count:
          type: integer
          format: int64
        event_name:
          type: string
    EventData:
      type: object
      title: EventData
      description: EventData represents a single analytics event
      required:
        - id
        - event_type
        - event_name
        - items
        - dataset_id
        - created_at
        - updated_at
      properties:
        created_at:
          type: string
          description: The time the event was created.
        dataset_id:
          type: string
          format: uuid
          description: The unique identifier for the dataset the event is associated with.
        event_name:
          type: string
          description: >-
            The name of the event, e.g. "Added to Cart", "Purchased", "Viewed
            Home Page", "Clicked", "Filter Clicked", "Followup Query".
        event_type:
          type: string
          description: >-
            The type of event, "add_to_cart", "purchase", "view", "click",
            "filter_clicked", "followup_query"
        id:
          type: string
          format: uuid
          description: The unique identifier for the event
        is_conversion:
          type: boolean
          description: Whether the event is a conversion event.
          nullable: true
        items:
          type: array
          items:
            type: string
          description: >-
            The items associated with the event. This could be a list of
            stringified json chunks for search events, or a list of items for
            add_to_cart, purchase, view, and click events.
        metadata:
          description: >-
            Additional metadata associated with the event. This can be custom
            data that is specific to the event.
          nullable: true
        request_id:
          type: string
          description: The unique identifier for the request the event is associated with.
          nullable: true
        request_type:
          type: string
          description: The type of request the event is associated with.
          nullable: true
        updated_at:
          type: string
          description: The time the event was last updated.
        user_id:
          type: string
          description: The user identifier associated with the event.
          nullable: true
      example:
        created_at: '2021-08-10T00:00:00Z'
        dataset_id: 00000000-0000-0000-0000-000000000000
        event_name: Viewed Home Page
        event_type: view
        is_conversion: true
        items:
          - item1
          - item2
        metadata: metadata
        request_id: 00000000-0000-0000-0000-000000000000
        updated_at: '2021-08-10T00:00:00Z'
        user_id: user1
    PopularChat:
      type: object
      required:
        - name
        - count
      properties:
        count:
          type: integer
          format: int64
        name:
          type: string
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: Authorization

````