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 resultsmodel(str): Model name usedtotal_usage(Usage): Total token usage across all inputs
EmbeddingData
text(str): Original input textembedding(List[float]): Vector embeddingusage(Usage): Token usage for this input
Usage
total_tokens(int): Total tokens processed
Getting an API Key
- Sign up at app.neuralex.ca
- Generate a new API key
- Keep your API key secure and never commit it to version control
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68381a5e9cd859c3c49fc27c84edbdbe98c2b51e02270324307de096255ca07e
|
|
| MD5 |
9fbfd630a4f09d209b50acbfc4c2cb42
|
|
| BLAKE2b-256 |
ecea02e93152937a4e8eff6055765a9cf69c52d94b1091675cc4fe87bdab880f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
631ec82bffc84271cbeb8e24c791c53097a4f66369571a609d6bab4aafadb01f
|
|
| MD5 |
0b236a91293461dd250b02162433f682
|
|
| BLAKE2b-256 |
f275cdcb7e9543d0e6fe92a496fffc7709e29cf5e0a38ff391232ee1e24e4a0c
|