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

# Replace a topic's tags

> Replace a topic's entire tag set with the ids you send.

`version` is the tag version you expect the topic to be at. The write is rejected if it has moved on, so a concurrent update cannot be silently lost.

- Duplicate ids collapse, and the first 50 distinct ids are stored. Sending 51–100 still succeeds — the response reports what was dropped.
- Sending the set a topic already carries is a no-op and does not advance the version.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v2/knowledge_bases/{kb_id}/documents/{doc_id}/topics/{topic_id}/tag/replace
openapi: 3.1.0
info:
  title: EverOS Cloud Memory API
  version: 2.0.0
  license:
    name: Apache-2.0
    identifier: Apache-2.0
  contact:
    name: EverMind AI
    email: service@evermind.ai
    url: https://github.com/EverMind-AI/everos-cloud-sdk-python
  description: >-
    Official Python client for the EverOS Cloud Memory API. Add, search,
    retrieve, and manage long-term memory for your AI applications over a typed
    interface (pydantic v2, with full type hints). Install and usage guides:
    https://github.com/EverMind-AI/everos-cloud-sdk-python
servers:
  - url: https://api.evermind.ai
    description: Production
security:
  - BearerAuth: []
paths:
  /api/v2/knowledge_bases/{kb_id}/documents/{doc_id}/topics/{topic_id}/tag/replace:
    post:
      tags:
        - Knowledge
      summary: Replace a topic's tags
      description: >-
        Replace a topic's entire tag set with the ids you send.


        `version` is the tag version you expect the topic to be at. The write is
        rejected if it has moved on, so a concurrent update cannot be silently
        lost.


        - Duplicate ids collapse, and the first 50 distinct ids are stored.
        Sending 51–100 still succeeds — the response reports what was dropped.

        - Sending the set a topic already carries is a no-op and does not
        advance the version.
      operationId: replaceTopicTags
      parameters:
        - name: kb_id
          in: path
          required: true
          schema:
            type: string
            title: Kb Id
        - name: doc_id
          in: path
          required: true
          schema:
            type: string
            title: Doc Id
        - name: topic_id
          in: path
          required: true
          schema:
            type: string
            title: Topic Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TopicTagReplaceBody'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessEnvelope_TopicTagWriteData_'
        '401':
          description: Missing or invalid bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '403':
          description: >-
            Authenticated but not permitted — either rejected by the auth
            service, or the account's memory API version does not match the
            interface version implied by the path (a v1 account calling an
            /api/v2 route).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '404':
          description: Topic absent or not owned by the path kb/document
        '409':
          description: Stale topic tag version (atomic zero-write conflict)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
        '429':
          description: Rate limit or quota exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
        '500':
          description: >-
            Storage or search projection failure. Mongo may already contain the
            snapshot; replay the same snapshot to converge.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '503':
          description: >-
            The gateway could not reach the authentication service. Transient —
            retry with backoff.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayError'
components:
  schemas:
    TopicTagReplaceBody:
      properties:
        tag_ids:
          items:
            type: string
            maxLength: 128
            minLength: 1
            description: Opaque semantic tag id
          type: array
          maxItems: 100
          title: Tag Ids
          description: >-
            Complete materialized snapshot. Cloud stable-deduplicates the
            request, stores the first 50 ids, and reports any truncation.
        version:
          type: integer
          minimum: 0
          title: Version
          description: Expected current topic tag_version (CAS)
      additionalProperties: false
      type: object
      required:
        - tag_ids
        - version
      title: TopicTagReplaceBody
    SuccessEnvelope_TopicTagWriteData_:
      properties:
        request_id:
          type: string
          title: Request Id
          description: Request trace id (peer to data)
        data:
          $ref: '#/components/schemas/TopicTagWriteData'
          description: Endpoint-defined business result
      type: object
      required:
        - request_id
        - data
      title: SuccessEnvelope[TopicTagWriteData]
    GatewayError:
      type: object
      additionalProperties: true
      description: >-
        Gateway error body. NOTE: shape is not yet uniform across auth/quota/
        rate-limit paths — treat fields as best-effort. Commonly includes a
        `code`/`message` (flat) or an `error` object/string with a `message`.
      title: GatewayError
    ErrorEnvelope:
      properties:
        request_id:
          type: string
          title: Request Id
          description: Request trace id
        error:
          $ref: '#/components/schemas/ErrorBody'
          description: Error detail (code + message)
      type: object
      required:
        - request_id
        - error
      title: ErrorEnvelope
      description: >-
        v1 error envelope (spec §1): ``{request_id, error:{code,message}}``.


        Used by ``global_exception_handler`` for both HTTPException (carrying
        the

        domain code via ``InvocationHttpError``) and unhandled exceptions.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          description: One entry per field that failed validation.
      type: object
      title: HTTPValidationError
    TopicTagWriteData:
      properties:
        topic_id:
          type: string
          title: Topic Id
          description: The topic whose tag snapshot was written.
        requested:
          type: integer
          minimum: 0
          title: Requested
          description: Stable-distinct request id count; not vocabulary-validity count
        tag_ids:
          items:
            type: string
            maxLength: 128
            minLength: 1
            description: Opaque semantic tag id
          type: array
          maxItems: 50
          uniqueItems: true
          title: Tag Ids
          description: Complete materialized topic tag snapshot after the accepted write
        version:
          type: integer
          minimum: 0
          title: Version
          description: Current topic tag version
        truncated:
          type: boolean
          title: Truncated
          description: Whether distinct input exceeded the store limit
        limit:
          type: integer
          const: 50
          title: Limit
          description: Materialized topic tag limit
        dropped_count:
          type: integer
          minimum: 0
          title: Dropped Count
          description: Distinct requested ids omitted by stable truncation
      additionalProperties: false
      type: object
      required:
        - topic_id
        - requested
        - tag_ids
        - version
        - truncated
        - limit
        - dropped_count
      title: TopicTagWriteData
    ErrorBody:
      properties:
        code:
          type: string
          title: Code
          description: Domain error code
        message:
          type: string
          title: Message
          description: Human-readable error message
      type: object
      required:
        - code
        - message
      title: ErrorBody
      description: Nested error object inside the error envelope.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
          description: Path to the offending field, from the body root.
        msg:
          type: string
          title: Message
          description: What is wrong with it.
        type:
          type: string
          title: Error Type
          description: Machine-readable validation-error kind.
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: 'API key issued by EverOS, sent as `Authorization: Bearer <api_key>`.'

````