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

# Delete a String

> Remove an embedded text snippet from a corpus.

## Overview

Permanently delete a text snippet resource along with its metadata and vector embeddings. This immediately removes the string content from search results and retrieval operations.

<Warning>
  **Irreversible**: Deletion cannot be undone. The string record and its vector embeddings are permanently removed.
</Warning>

<Info>
  **Use cases**: Retracting outdated guidance, removing obsolete policies, correcting misinformation, or managing corpus content quality.
</Info>

## Authentication

Requires valid JWT token or session authentication. You must own the parent corpus.

## Path Parameters

<ParamField path="id" type="UUID" required>
  String resource identifier. Must belong to a corpus you own.

  **Example**: `b43bbf35-9819-47a8-8aff-d4eb4b3e8219`
</ParamField>

## Example request

```bash theme={null}
curl -X DELETE https://{your-host}/api/data/strings/b43bbf35-9819-47a8-8aff-d4eb4b3e8219/ \
  -H "Authorization: Bearer $SOAR_LABS_TOKEN"
```

## Response Codes

<ResponseField name="204" type="No Content">
  String successfully deleted. No response body returned.
</ResponseField>

<ResponseField name="404" type="Not Found">
  String does not exist, was already deleted, or belongs to a corpus you don't own.
</ResponseField>

## What Gets Deleted

* **String record** - Database entry with title and content
* **Vector embeddings** - All chunks removed from Qdrant
* **Metadata** - Creation timestamp and character count

<Note>
  **Immediate effect**: Vector cleanup happens synchronously, so deletions immediately affect retrieval quality and query results.
</Note>

## Verification

Confirm successful deletion:

```bash theme={null}
# This should return 404 after deletion
curl -X GET https://{your-host}/api/data/strings/{string-id}/ \
  -H "Authorization: Bearer $SOAR_LABS_TOKEN"
```

## Common Use Cases

<AccordionGroup>
  <Accordion title="Batch String Deletion" icon="list">
    Remove multiple strings matching criteria:

    ```python theme={null}
    # Get all strings in corpus
    strings = requests.get(
        f"{base_url}/api/data/strings/?corpora={corpus_id}",
        headers=headers
    ).json()

    # Delete outdated strings
    deleted_count = 0
    for string in strings["results"]:
        # Example: Delete strings containing specific keyword
        if "[DEPRECATED]" in string["title"]:
            try:
                response = requests.delete(
                    f"{base_url}/api/data/strings/{string['id']}/",
                    headers=headers
                )
                if response.status_code == 204:
                    deleted_count += 1
                    print(f"Deleted: {string['title']}")
            except Exception as e:
                print(f"Failed to delete {string['title']}: {e}")

    print(f"Total deleted: {deleted_count}")
    ```
  </Accordion>

  <Accordion title="Replace Outdated Content" icon="arrows-rotate">
    Update guidance by deleting old version and adding new:

    ```python theme={null}
    # Step 1: Delete outdated string
    requests.delete(
        f"{base_url}/api/data/strings/{old_string_id}/",
        headers=headers
    )

    # Step 2: Add updated content
    response = requests.post(
        f"{base_url}/api/data/strings/",
        headers=headers,
        json={
            "corpora": corpus_id,
            "strings": [{
                "title": "Updated SLA Policy",
                "string": "Critical tickets must be responded to within 5 minutes (updated Q4 2024)."
            }]
        }
    )

    new_string = response.json()[0]
    print(f"New string ID: {new_string['id']}")
    ```

    <Tip>
      **Version tracking**: Include version dates or identifiers in string titles for easy tracking and replacement.
    </Tip>
  </Accordion>

  <Accordion title="Clean Up Duplicates" icon="clone">
    Find and remove duplicate string content:

    ```python theme={null}
    # Get all strings
    strings = requests.get(
        f"{base_url}/api/data/strings/?corpora={corpus_id}",
        headers=headers
    ).json()["results"]

    # Find duplicates by content
    seen_content = {}
    duplicates = []

    for string in strings:
        content = string["string"].strip().lower()
        if content in seen_content:
            duplicates.append(string["id"])
            print(f"Duplicate found: {string['title']}")
        else:
            seen_content[content] = string["id"]

    # Delete duplicates
    for dup_id in duplicates:
        requests.delete(
            f"{base_url}/api/data/strings/{dup_id}/",
            headers=headers
        )

    print(f"Removed {len(duplicates)} duplicate strings")
    ```
  </Accordion>

  <Accordion title="Policy Retraction Workflow" icon="gavel">
    Safely retract policy or guidance:

    ```python theme={null}
    # Step 1: Verify string content before deletion
    string = requests.get(
        f"{base_url}/api/data/strings/{string_id}/",
        headers=headers
    ).json()

    print(f"Title: {string['title']}")
    print(f"Content: {string['string'][:100]}...")
    print(f"Created: {string['created_at']}")

    # Step 2: Log the deletion for audit trail
    audit_log = {
        "action": "string_deletion",
        "string_id": string_id,
        "title": string["title"],
        "timestamp": datetime.now().isoformat(),
        "reason": "Policy superseded by new guidance"
    }

    # Save audit log
    with open("deletion_audit.json", "a") as f:
        f.write(json.dumps(audit_log) + "\n")

    # Step 3: Delete the string
    response = requests.delete(
        f"{base_url}/api/data/strings/{string_id}/",
        headers=headers
    )

    if response.status_code == 204:
        print("String retracted successfully")
        print("Audit log saved")
    ```

    **Compliance note**: Maintain audit logs for all content deletions to meet regulatory requirements.
  </Accordion>

  <Accordion title="Selective Corpus Cleanup" icon="broom">
    Clean up strings based on age or usage:

    ```python theme={null}
    from datetime import datetime, timedelta

    # Get all strings
    strings = requests.get(
        f"{base_url}/api/data/strings/?corpora={corpus_id}",
        headers=headers
    ).json()["results"]

    # Delete strings older than 1 year
    cutoff_date = datetime.now() - timedelta(days=365)
    old_strings = []

    for string in strings:
        created = datetime.fromisoformat(string["created_at"].replace("Z", "+00:00"))
        if created < cutoff_date:
            old_strings.append(string)

    print(f"Found {len(old_strings)} strings older than 1 year")

    # Delete with confirmation
    if input("Proceed with deletion? (yes/no): ") == "yes":
        for string in old_strings:
            requests.delete(
                f"{base_url}/api/data/strings/{string['id']}/",
                headers=headers
            )
        print(f"Deleted {len(old_strings)} old strings")
    ```
  </Accordion>
</AccordionGroup>

<Tip>
  **Content quality**: Regularly review and remove outdated strings to maintain high-quality retrieval results and corpus relevance.
</Tip>

## Client examples

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    import os
    import requests

    BASE_URL = "https://your-soar-instance.com"
    TOKEN = os.environ["SOAR_LABS_TOKEN"]
    STRING_ID = "b43bbf35-9819-47a8-8aff-d4eb4b3e8219"

    response = requests.delete(
        f"{BASE_URL}/api/data/strings/{STRING_ID}/",
        headers={"Authorization": f"Bearer {TOKEN}"},
        timeout=30,
    )
    if response.status_code != 204:
        response.raise_for_status()
    ```
  </Tab>

  <Tab title="TypeScript / JavaScript">
    ```ts theme={null}
    const BASE_URL = "https://your-soar-instance.com";
    const token = process.env.SOAR_LABS_TOKEN!;

    async function deleteString(stringId: string) {
      const response = await fetch(`${BASE_URL}/api/data/strings/${stringId}/`, {
        method: "DELETE",
        headers: {
          Authorization: `Bearer ${token}`,
        },
      });

      if (response.status !== 204) {
        throw new Error(`Delete string failed: ${response.status}`);
      }
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    import java.net.URI;
    import java.net.http.HttpClient;
    import java.net.http.HttpRequest;
    import java.net.http.HttpResponse;

    var BASE_URL = "https://your-soar-instance.com";
    var token = System.getenv("SOAR_LABS_TOKEN");
    var stringId = "b43bbf35-9819-47a8-8aff-d4eb4b3e8219";

    var request = HttpRequest.newBuilder(URI.create(BASE_URL + "/api/data/strings/" + stringId + "/"))
        .header("Authorization", "Bearer " + token)
        .DELETE()
        .build();

    var response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.discarding());

    if (response.statusCode() != 204) {
        throw new RuntimeException("Delete string failed: " + response.statusCode());
    }
    ```
  </Tab>
</Tabs>


## OpenAPI

````yaml DELETE /api/data/strings/{id}/
openapi: 3.0.3
info:
  title: Soar Labs API - Insider Dev preview
  version: 0.1.0
  description: <b>Soar Labs Advanced RAG platform</b>
servers: []
security: []
paths:
  /api/data/strings/{id}/:
    delete:
      tags:
        - Resources
      description: >-
        String creation API using Django Rest Framework.


        This viewset provides CRUD operations for String objects associated with
        a Corpora.


        ### Request Body

        ```

        {
            "corpora": "e6e8285a-2b97-48af-930b-441c502cd45e",
            "strings": [
                {
                    "title": "String 1 Title",
                    "string": "This is the first string content."
                },
                {
                    "title": "String 2 Title",
                    "string": "This is the second string content."
                },
                {
                    "title": "String 3 Title",
                    "string": "This is the third string content."
                }
            ]
        }

        ```


        ### Responses


        - **201 Created**: Returned on successful creation of a String.

        - **400 Bad Request**: Returned if the request data is invalid.

        - **401 Unauthorized**: Returned if the user is not authenticated.

        - **403 Forbidden**: Returned if the user is not authorized to perform
        the operation.

        - **404 Not Found**: Returned if the requested Corpora does not exist.


        ### Response Body

        ```

        [
            {
                "id": "b43bbf35-9819-47a8-8aff-d4eb4b3e8219",
                "created_at": "2024-09-01T10:19:59.709807Z",
                "updated_at": "2024-09-01T10:19:59.709922Z",
                "is_indexed": false,
                "indexed_on": null,
                "title": "String 1 Title",
                "string": "This is the first string content.",
                "character_count": 33,
                "corpora": "e6e8285a-2b97-48af-930b-441c502cd45e"
            },
            {
                "id": "2f3c3748-173a-4ace-875d-cff12d5d71ee",
                "created_at": "2024-09-01T10:19:59.710042Z",
                "updated_at": "2024-09-01T10:19:59.710057Z",
                "is_indexed": false,
                "indexed_on": null,
                "title": "String 2 Title",
                "string": "This is the second string content.",
                "character_count": 34,
                "corpora": "e6e8285a-2b97-48af-930b-441c502cd45e"
            },
            {
                "id": "a86c7368-a8b4-4910-9c3c-2501f8e0d0fc",
                "created_at": "2024-09-01T10:19:59.710115Z",
                "updated_at": "2024-09-01T10:19:59.710128Z",
                "is_indexed": false,
                "indexed_on": null,
                "title": "String 3 Title",
                "string": "This is the third string content.",
                "character_count": 33,
                "corpora": "e6e8285a-2b97-48af-930b-441c502cd45e"
            }
        ]

        ```
      operationId: api_data_strings_destroy
      parameters:
        - in: path
          name: id
          schema:
            type: string
            format: uuid
          description: A UUID string identifying this String.
          required: true
      responses:
        '204':
          description: No response body
      security:
        - jwtHeaderAuth: []
        - jwtCookieAuth: []
        - cookieAuth: []
        - basicAuth: []
components:
  securitySchemes:
    jwtHeaderAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    jwtCookieAuth:
      type: apiKey
      in: cookie
      name: soar-app-auth
    cookieAuth:
      type: apiKey
      in: cookie
      name: sessionid
    basicAuth:
      type: http
      scheme: basic

````