InstructorEmbeddings is a Python library that simplifies the generation of high-quality text embeddings using the INSTRUCTOR family of models. It's built upon `sentence-transformers` and Hugging Face `transformers`, providing an easy-to-use interface to leverage instruction-tuned embeddings. Currently at version 1.0.1, it has an active development status with releases as new models or features are integrated.
pip install InstructorEmbeddingVerified import paths — ran on the pinned version, not inferred.
Initialize an INSTRUCTOR model, provide a suitable instruction, and encode text to generate embeddings. The model will be downloaded on first use.
Be prepared for an initial download time. For offline use, pre-download models or manage the cache directory with `HUGGINGFACE_HUB_CACHE` environment variable.
Initialize the model with `device='cuda'` if a GPU is available: `model = INSTRUCTOR('hkunlp/instructor-xl', device='cuda')`.Consider using smaller models from the INSTRUCTOR family (e.g., `hkunlp/instructor-large`, `hkunlp/instructor-base`) or implement batching/quantization if supported, or ensure sufficient GPU memory is available.
Always provide a task-specific instruction as the first element in the input list (e.g., `model.encode([['instruction', 'sentence']])`). Refer to the official documentation for instruction examples for various tasks.