Skip to main content

Official Python client library for NeuraLex API

Project description

NeuraLex Python Client

Official Python client library for the NeuraLex API.

Installation

pip install neuralex

Quick Start

from neuralex import NeuraLexClient

# Initialize client with your API key
client = NeuraLexClient(api_key="nlx_your_api_key")

# Generate embeddings
response = client.embed("Hello, world!")

# Access the embedding vector
embedding = response.payload[0].embedding
print(f"Dimensions: {len(embedding)}")
print(f"First 5 values: {embedding[:5]}")

Features

  • ✅ Simple and intuitive API
  • ✅ Synchronous and asynchronous support
  • ✅ Type hints and Pydantic models
  • ✅ Automatic error handling
  • ✅ Configurable semantic/term-based balance
  • ✅ Batch embedding support (up to 100 inputs)

Usage

Basic Usage

from neuralex import NeuraLexClient

client = NeuraLexClient(api_key="nlx_your_api_key")

# Single text
response = client.embed("Machine learning is fascinating")
embedding = response.payload[0].embedding

Batch Embeddings

# Multiple texts
texts = [
    "First document",
    "Second document",
    "Third document"
]
response = client.embed(texts)

for item in response.payload:
    print(f"Text: {item.text}")
    print(f"Embedding dimensions: {len(item.embedding)}")
    print(f"Tokens used: {item.usage.total_tokens}")

Adjusting Semantic Weight

The semantic_weight parameter controls the balance between term-based and semantic embeddings:

  • 0.0 = Pure term-based (exact keyword matching)
  • 1.0 = Pure semantic (meaning-based)
  • 0.5 = Balanced (default)
# More term-focused (better for keyword search)
response = client.embed(
    "Python programming",
    semantic_weight=0.3
)

# More semantic-focused (better for meaning-based search)
response = client.embed(
    "Python programming",
    semantic_weight=0.8
)

Using Context Manager

# Automatically handles connection cleanup
with NeuraLexClient(api_key="nlx_your_api_key") as client:
    response = client.embed("Hello, world!")
    print(response.payload[0].embedding[:5])

Async Usage

import asyncio
from neuralex import AsyncNeuraLexClient

async def main():
    async with AsyncNeuraLexClient(api_key="nlx_your_api_key") as client:
        response = await client.embed(["Text 1", "Text 2", "Text 3"])
        for item in response.payload:
            print(f"{item.text}: {len(item.embedding)} dimensions")

asyncio.run(main())

Error Handling

from neuralex import NeuraLexClient, AuthenticationError, RateLimitError, APIError

client = NeuraLexClient(api_key="nlx_your_api_key")

try:
    response = client.embed("Hello, world!")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded, please wait")
except APIError as e:
    print(f"API error: {e.message} (status: {e.status_code})")
except Exception as e:
    print(f"Unexpected error: {e}")

API Reference

NeuraLexClient

Main client class for synchronous API calls.

Methods:

  • embed(inputs, model="public", language="english", semantic_weight=0.5) - Generate embeddings

Parameters:

  • inputs (str | List[str]): Text or list of texts to embed (max 100)
  • model (str, optional): Model name (default: "public")
  • language (str, optional): Language for lexeme extraction (default: "english")
  • semantic_weight (float, optional): Balance between term (0.0) and semantic (1.0) (default: 0.5)

Returns: EmbeddingResponse object

AsyncNeuraLexClient

Async client class for asynchronous API calls. Same interface as NeuraLexClient but all methods are async.

Models

EmbeddingResponse

  • payload (List[EmbeddingData]): List of embedding results
  • model (str): Model name used
  • total_usage (Usage): Total token usage across all inputs

EmbeddingData

  • text (str): Original input text
  • embedding (List[float]): Vector embedding
  • usage (Usage): Token usage for this input

Usage

  • total_tokens (int): Total tokens processed

Getting an API Key

  1. Sign up at app.neuralex.ca
  2. Generate a new API key
  3. Keep your API key secure and never commit it to version control

License

MIT License - see LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

neuralex-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

neuralex-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file neuralex-0.1.0.tar.gz.

File metadata

  • Download URL: neuralex-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for neuralex-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68381a5e9cd859c3c49fc27c84edbdbe98c2b51e02270324307de096255ca07e
MD5 9fbfd630a4f09d209b50acbfc4c2cb42
BLAKE2b-256 ecea02e93152937a4e8eff6055765a9cf69c52d94b1091675cc4fe87bdab880f

See more details on using hashes here.

File details

Details for the file neuralex-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: neuralex-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for neuralex-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 631ec82bffc84271cbeb8e24c791c53097a4f66369571a609d6bab4aafadb01f
MD5 0b236a91293461dd250b02162433f682
BLAKE2b-256 f275cdcb7e9543d0e6fe92a496fffc7709e29cf5e0a38ff391232ee1e24e4a0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page