openaivec
CLAUDE.md25 starsChanged 9 days agoMITView on GitHub
This is openaivec, a Python library that enables AI-powered text processing at scale for pandas DataFrames and Apache Spark. The project provides vectorized OpenAI API access, reducing latency and API costs through batch processing and automatic deduplication.
- Reads credentials
- Installs packages
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- openaivec-skillSkill
The file
Show its rules and text
We split this CLAUDE.md into the rules it gives an agent
19 rules. About 0 are common, 7 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Use Python 3.11 or newer for the library and all development tooling.
- Distinctive: line 56
Vectorization: All API calls are batched to reduce latency and costs
- Very specific: line 97
Spark Integration: Update spark_ext.py for distributed processing features
- Very specific: line 98
New Task Domains: Add modules under task/ following existing patterns
- Distinctive: line 105
Test both sync and async variants where applicable
- Very specific: line 107
Run specific module tests: uv run pytest tests/test_[module_name].py -v
- Very specific: line 114
Update mkdocs.yml navigation when adding new modules or examples
- Distinctive: line 118
Docstrings: Use Google-style docstrings for all public functions, classes, and methods
- Very specific: line 119
All Args sections must include type information in parentheses (e.g., parameter_name (str): Description)
- Distinctive: line 121
Type Annotations: Use modern Python type syntax throughout the codebase
- Very specific: line 122
Built-in Generic Types: Use built-in generic types instead of typing module equivalents:
- Very specific: line 128
Union Types: Use | union syntax instead of Union[...] (e.g., int | str | None)
- Very specific: line 130
Collections.abc: Use collections.abc for abstract types:
- Distinctive: line 135
Comments: Avoid adding comments unless explicitly requested
- Very specific: line 138
MUST use absolute imports: - All imports within the project must use absolute paths (e.g., from openaivec.responses import BatchResponses)
- Very specific: line 139
Never use relative imports (e.g., from .responses import ...
- Very specific: line 147
Default model: gpt-4.1-mini for responses, text-embedding-3-small for embeddings
- Distinctive: line 151
When using Azure OpenAI, always use the v1 API format:
- Very specific: line 197
Internal modules: Use __all__ = [] to explicitly mark as internal-only
≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is openaivec, a Python library that enables AI-powered text processing at scale for pandas DataFrames and Apache Spark. The project provides vectorized OpenAI API access, reducing latency and API costs through batch processing and automatic deduplication.
Development Commands
Dependencies and Environment
Use Python 3.11 or newer for the library and all development tooling.
# Install all dependencies (development and optional extras)
uv sync --all-extras --dev
# Install package in development mode
uv pip install -e .Code Quality and Testing
# Run linting and formatting (check, auto-fix, and format)
uv run ruff check . --fix && uv run ruff format .
# Run tests
uv run pytest
# Run tests for a specific module
uv run pytest tests/test_[module_name].pyDocumentation
# Build and serve documentation locally (uses MkDocs)
uv run mkdocs serve
# Build documentation for deployment
uv run mkdocs buildArchitecture and Structure
Core Components
- BatchResponses/AsyncBatchResponses (
src/openaivec/responses.py): Vectorized API interface for OpenAI completions - BatchEmbeddings/AsyncBatchEmbeddings (
src/openaivec/embeddings.py): Vectorized embedding generation - pandas_ext (
src/openaivec/pandas_ext/): Pandas DataFrame/Series extensions with.ai/.aioaccessors - spark (
src/openaivec/spark_ext.py): Apache Spark UDF builders for distributed processing - task (
src/openaivec/task/): Pre-built task modules for NLP and customer support domains - di (
src/openaivec/di.py): Simple dependency injection container with singleton lifecycle management
Key Architecture Patterns
- Vectorization: All API calls are batched to reduce latency and costs
- Deduplication: Automatic removal of duplicate inputs to minimize API usage
- Structured Output: Pydantic model support for type-safe responses
- Extensibility: Modular task system for domain-specific operations
Package Structure
src/openaivec/
├── __init__.py # Main exports (public API)
├── pandas_ext/ # Pandas integration (public, package)
│ ├── __init__.py # Re-exports public API, registers accessors
│ ├── _common.py # Shared helpers
│ ├── _config.py # Client/model configuration
│ ├── _series_sync.py # .ai Series accessor
│ ├── _dataframe_sync.py # .ai DataFrame accessor
│ ├── _series_async.py # .aio Series accessor
│ └── _dataframe_async.py # .aio DataFrame accessor
├── spark_ext.py # Spark UDF builders (public)
├── _di.py # Dependency injection container (internal)
├── _embeddings.py # Batch embedding processing (internal)
├── _log.py # Logging configuration (internal)
├── _model.py # Task configuration models (internal)
├── _optimize.py # Performance optimization (internal)
├── _prompt.py # Few-shot prompt building (internal)
├── _provider.py # Client provider and configuration (internal)
├── _proxy.py # Batch processing proxies (internal)
├── _responses.py # Batch response processing (internal)
├── _serialize.py # Serialization utilities (internal)
├── _util.py # General utilities (internal)
└── task/ # Pre-built task modules (public)
├── nlp/ # NLP tasks (translation, sentiment, etc.)
├── customer_support/ # Customer support tasks
└── table/ # Table-specific operations (fillna, etc.)Development Workflow
Adding New Features
- Core API Changes: Modify
_responses.pyor_embeddings.pyfor API-level features - Pandas Integration: Extend
pandas_ext/sub-modules for DataFrame/Series functionality - Spark Integration: Update
spark_ext.pyfor distributed processing features - New Task Domains: Add modules under
task/following existing patterns - Dependency Injection: Modify
_di.pyfor service lifecycle management
Testing Strategy
- Unit tests in
tests/mirror thesrc/structure - Integration tests require
OPENAI_API_KEYenvironment variable - Test both sync and async variants where applicable
- Mock API responses for deterministic testing when needed
- Run specific module tests:
uv run pytest tests/test_[module_name].py -v - Type Checking:
uv run pyright src/openaivec- enforced in CI with gradual improvement targets
Documentation Updates
- API documentation is auto-generated from docstrings using
mkdocstrings - Examples in
docs/examples/are Jupyter notebooks - Update
mkdocs.ymlnavigation when adding new modules or examples
Code Style Guidelines
- Docstrings: Use Google-style docstrings for all public functions, classes, and methods
- All Args sections must include type information in parentheses (e.g.,
parameter_name (str): Description) - Maintain consistency across all modules for better developer experience
- All Args sections must include type information in parentheses (e.g.,
- Type Annotations: Use modern Python type syntax throughout the codebase
- Built-in Generic Types: Use built-in generic types instead of
typingmodule equivalents:list[T]instead ofList[T]dict[K, V]instead ofDict[K, V]set[T]instead ofSet[T]tuple[T, ...]instead ofTuple[T, ...]type[T]instead ofType[T]
- Union Types: Use
|union syntax instead ofUnion[...](e.g.,int | str | None) - Optional Types: MUST use
S | Noneinstead ofOptional[S]- Always use the modern union syntax for optional types - Collections.abc: Use
collections.abcfor abstract types:collections.abc.Callableinstead oftyping.Callablecollections.abc.Awaitableinstead oftyping.Awaitablecollections.abc.Iteratorinstead oftyping.Iterator
- Apply comprehensive type annotations to function signatures and variables
- Built-in Generic Types: Use built-in generic types instead of
- Comments: Avoid adding comments unless explicitly requested
- Classes: Use
@dataclassfor all classes — including wrappers, backends, and caches. Every field must have an explicit type annotation. Use Pydantic only at validation boundaries (API responses, task models). Never create collaborators inside__init__/__post_init__; accept them as typed dataclass fields (dependency injection) so they can be swapped or mocked. Provide a@classmethod of(...)factory for convenient construction with sensible defaults. - Imports:
- MUST use absolute imports - All imports within the project must use absolute paths (e.g.,
from openaivec.responses import BatchResponses) - Never use relative imports (e.g.,
from .responses import ...orfrom ..task import ...) - Exception:
__init__.pyfiles may use relative imports for re-exporting modules within the same package - This rule applies to all other modules including test files
- MUST use absolute imports - All imports within the project must use absolute paths (e.g.,
Important Implementation Notes
OpenAI Client Configuration
- Supports both OpenAI and Azure OpenAI clients
- Default model:
gpt-4.1-minifor responses,text-embedding-3-smallfor embeddings - API key managed via
OPENAI_API_KEYenvironment variable
Azure OpenAI Standard Configuration
When using Azure OpenAI, always use the v1 API format:
- Base URL:
https://YOUR-RESOURCE-NAME.services.ai.azure.com/openai/v1/ - Example environment variables:
os.environ["AZURE_OPENAI_API_KEY"] = "your-azure-key" os.environ["AZURE_OPENAI_BASE_URL"] = "https://YOUR-RESOURCE-NAME.services.ai.azure.com/openai/v1/" - Omit
AZURE_OPENAI_API_KEYto authenticate via Entra ID (DefaultAzureCredential).
Performance Considerations
- Batch processing reduces API calls by ~90% on typical datasets
- Automatic deduplication can save 50-90% of API costs
- Batch sizes are automatically optimized by default for optimal throughput
Error Handling
- Graceful degradation when API limits are hit
- Proper serialization handling for complex data types
- Comprehensive logging for debugging batch operations
Package Visibility Guidelines (__all__)
Public API Modules
These modules are part of the public API and have appropriate __all__ declarations:
pandas_ext/- Pandas DataFrame/Series extensions with.ai/.aioaccessors (package)spark_ext.py- Apache Spark UDF builders for distributed processingtask/*- All task modules (NLP, customer support, table operations)
Internal Modules (underscore-prefixed)
These modules are for internal use only and have __all__ = []:
_embeddings.py- Batch embedding processing (internal implementation)_model.py- Task configuration models (internal types)_prompt.py- Few-shot prompt building (internal implementation)_responses.py- Batch response processing (internal implementation)_util.py,_serialize.py,_log.py,_provider.py,_proxy.py,_di.py,_optimize.py- Internal utilities
Main Package API
Users access core functionality through __init__.py exports:
BatchResponses,AsyncBatchResponsesBatchEmbeddings,AsyncBatchEmbeddingsPreparedTask,FewShotPromptBuilder
__all__ Best Practices
- Public modules: Include all classes, functions, and constants intended for external use
- Internal modules: Use
__all__ = []to explicitly mark as internal-only - Task modules: Each task module should export its main classes/functions
- Package
__init__.py: Re-export public API from all public modules - Consistency: Maintain alphabetical ordering within
__all__lists
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

