Python SDK Guide

A Python client library for interacting with the NeoAthena API, providing functionality to create and manage collections, upload files, and perform document retrieval operations.

Requirements:

Python 3.8+ (Ensure you have a compatible version installed)

You’ll need an API key to get started. Visit our website to get your api key

Installation:

install the package:

pip install neoathena

API Reference:

1. Create a Collection and Upload Files

Upload a file to the collection. Upload endpoint creates a new collection if it doesn't exist.

from neoathena import NeoAthenaClient

client = NeoAthenaClient(api_key="your-api-key")
try:
    results = client.upload_to_collection(
        collection_name="your-collection-name",
        filepath="path/to/your/file"
    )
    print(results)
except Exception as e:
    print(f"Upload failed: {e}")

Sample Response:

When the request is successful, you will receive an unique document ID in the response.

{
  "status": "File uploaded",
  "collection": "your-collection-name",
  "document_id": document-id,
  "metadata": {
    "user": "your-email",
    "type": "file-type",
    "size": file-size
  }
}

2. Retrieving Documents

Retrieve information from the collection based on search query.

try:
    results = client.retrieve_from_collection(
        collection_name="your-collection-name",
        query="your search query",
        top_k=4
    )
    print(results)
except Exception as e:
    print(f"Retrieval failed: {e}")

Sample Response:

[
    Document(
        metadata={
            "source": "file-path",
            "filename": "file-name",
            "_id": "unique-document-id",
            "_collection_name": "collection-name",
            "document_id": document-id
        },
        page_content="Extracted document content"
    ),
]

3. Deleting Documents

Delete a specific document:

try:
    response = client.delete_from_collection(
        collection_name="your-collection-name",
        doc_id=your_document_no
    )
    print(response)
except Exception as e:
    print(f"Document deletion failed: {e}")

Delete all documents:

try:
    response = client.delete_from_collection(
        collection_name="your-collection-name",
        doc_id=0,
        delete_all=True
    )
    print(response)
except Exception as e:
    print(f"Collection cleanup failed: {e}")

Sample Response:

true

4. Deleting a Collection

Delete an entire collection.

try:
    response = client.delete_collection(collection_name="your-collection-name")
    print(response)
except Exception as e:
    print(f"Collection deletion failed: {e}")

Sample Response:

true

5. List user collection

Gets all collections for a user.

try:
    response = client.get_collections()
    print(response)
except Exception as e:
    print(f"Fetching collections failed: {e}")

Sample Response:

[
    Collection(
        id=collection-id,
        user_id=user-id,
        name='collection-name',
        created_on=timestamp,
        last_updated=timestamp,
        documents=[
            Document(
                id=document-id,
                user_id=user-id,
                type='doucment-type',
                name='document-name',
                created_on=timestamp,
                updated_on=timestamp
            )
        ]
    ),
]

Last updated

Was this helpful?