Metal Python SDK

2.5.1 · active · verified Thu Apr 16

metal-sdk is the official Python SDK for getmetal.io, a managed service for ML Embeddings and an AI-first datastore & retrieval engine. It allows developers to easily integrate Metal's capabilities, such as semantic search and building AI-powered applications, into their Python projects. The current version is 2.5.1, released on November 10, 2023, with the broader Metal platform actively maintained and updated.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Metal client using API credentials and demonstrates how to index a simple text document and perform a basic search. It's crucial to replace placeholder credentials or set them as environment variables.

import os
from metal_sdk.metal import Metal

# It's recommended to load credentials from environment variables
api_key = os.environ.get('METAL_API_KEY', 'your_api_key_here')
client_id = os.environ.get('METAL_CLIENT_ID', 'your_client_id_here')
index_id = os.environ.get('METAL_INDEX_ID', 'your_index_id_here')

if not all([api_key, client_id, index_id]):
    print("Warning: API_KEY, CLIENT_ID, or INDEX_ID are missing. Please set environment variables or replace placeholders.")
    exit(1)

metal = Metal(api_key, client_id, index_id)

try:
    # Example: Indexing a document
    response = metal.index({"text": "The quick brown fox jumps over the lazy dog."})
    print(f"Document indexed successfully. ID: {response['data']['id']}")

    # Example: Searching for documents
    search_results = metal.search(text="quick fox", limit=1)
    if search_results and search_results['data']:
        print(f"Search result: {search_results['data'][0]['text']}")
    else:
        print("No search results found.")

except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →