Skip to main content

openai plugin for embcli

Project description

embcli-openai

openai plugin for embcli, a command-line interface for embeddings.

Reference

Installation

pip install embcli-openai

Quick Start

You need OpenAI API key to use this plugin. Set OPENAI_API_KEY environment variable in .env file in the current directory. Or you can give the env file path by -e option.

cat .env
OPENAI_API_KEY=<YOUR_OPENAI_KEY>

Try out the Embedding Models

# show general usage of emb command.
emb --help

# list all available models.
emb models
OpenAIEmbeddingModel
    Vendor: openai
    Models:
    * text-embedding-3-small (aliases: 3-small)
    * text-embedding-3-large (aliases: 3-large)
    * text-embedding-ada-002 (aliases: ada-002)
    Model Options:
    * dimensions (int) - The number of dimensions the resulting output embeddings should have. Only supported in text-embedding-3 and later models.

# get an embedding for an input text by text-embedding-3-small model.
emb embed -m 3-small "Embeddings are essential for semantic search and RAG apps."

# get an embedding for an input text by text-embedding-3-small model with dimensions=512.
emb embed -m 3-small "Embeddings are essential for semantic search and RAG apps." -o dimensions 512

# calculate similarity score between two texts by text-embedding-3-small model. the default metric is cosine similarity.
emb simscore -m 3-small "The cat drifts toward sleep." "Sleep dances in the cat's eyes."
0.6082515648413913

Document Indexing and Search

You can use the emb command to index documents and perform semantic search. emb uses chroma for the default vector database.

# index example documents in the current directory.
emb ingest-sample -m 3-small -c catcafe --corpus cat-names

# or, you can give the path to your documents.
# the documents should be in a CSV file with two columns: id and text. the separator should be comma.
emb ingest -m 3-small -c catcafe -f <path-to-your-documents>

# search for a query in the indexed documents.
emb search -m 3-small -c catcafe -q "Who's the naughtiest one?"
Found 5 results:
Score: 0.4130458064043753, Document ID: 20, Text: Pepper: Pepper is a feisty and energetic grey tabby with a spicy personality. She is quick-witted and loves to engage in playful stalking and pouncing games. Pepper is also fiercely independent but will show her affection with sudden bursts of purring and head-butts, keeping her humans on their toes.
Score: 0.41092058398810277, Document ID: 72, Text: Bea: Bea is a sweet and gentle calico, as lovely as a busy bee in a garden. She enjoys quiet observation and sunbathing, but also has a playful side, especially with feather wands. Bea is affectionate and loves a warm lap, her soft purrs a comforting hum, a truly delightful companion.
Score: 0.4099998098731923, Document ID: 25, Text: Nala: Nala is a graceful and queenly cat, often a beautiful cream or light tan color. She moves with quiet dignity and observes her surroundings with intelligent eyes. Nala is affectionate but discerning, choosing her moments for cuddles, and her loyalty to her family is unwavering, a truly regal companion.
Score: 0.40864073184452354, Document ID: 97, Text: Alfie: Alfie is a cheerful and mischievous little cat, always getting into playful trouble with a charming innocence. He loves exploring small spaces and batting at dangling objects. Alfie is incredibly affectionate, quick to purr and eager for cuddles, a delightful bundle of joy and entertainment for his humans.
Score: 0.4081247525728411, Document ID: 46, Text: Bandit: Bandit is a mischievous cat, often with mask-like markings, always on the lookout for his next playful heist of a toy or treat. He is clever and energetic, loving to chase and pounce. Despite his roguish name, Bandit is a loving companion who enjoys a good cuddle after his adventures.

Development

See the main README for general development instructions.

Run Tests

You need to have an OpenAI API key to run the tests for the embcli-openai package. You can set it up as an environment variable:

OPENAI_API_KEY=<YOUR_OPENAI_KEY> RUN_OPENAI_TESTS=1 uv run --package embcli-openai pytest packages/embcli-openai/tests/

Run Linter and Formatter

uv run ruff check --fix packages/embcli-openai
uv run ruff format packages/embcli-openai

Run Type Checker

uv run --package embcli-openai pyright packages/embcli-openai

Build

uv build --package embcli-openai

License

Apache License 2.0

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

embcli_openai-0.0.5.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

embcli_openai-0.0.5-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file embcli_openai-0.0.5.tar.gz.

File metadata

  • Download URL: embcli_openai-0.0.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for embcli_openai-0.0.5.tar.gz
Algorithm Hash digest
SHA256 4e32eab3f35ed82f32038b9dfafbaed13a035c27c3cba2f813df38f69490cfdd
MD5 01dc5a580ae520aecc38d2f29e3d8cd9
BLAKE2b-256 88882aab8e1613660dc7087eae891c976c0c8e1e15aa2aa7613758c7b56c1fe6

See more details on using hashes here.

File details

Details for the file embcli_openai-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for embcli_openai-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d99d3c7f79b1e1d44f0498d8c228fb30420c2f21358be325fc7afee32d557ba4
MD5 e84c95a956821f1c45d4cd4c01ce086a
BLAKE2b-256 0b12f022150645103938b8e3bf817ef1eb2716e8e6f35db5c7be440221a4ad0d

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