{"id":14983561,"url":"https://github.com/llukas22/tei-client","last_synced_at":"2025-10-12T21:05:04.004Z","repository":{"id":254444150,"uuid":"845538199","full_name":"LLukas22/tei-client","owner":"LLukas22","description":"Convenience Client for Hugging Face Text Embeddings Inference (TEI) with synchronous and asynchronous HTTP/gRPC support","archived":false,"fork":false,"pushed_at":"2025-01-28T12:58:47.000Z","size":135,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T19:45:07.393Z","etag":null,"topics":["client","embeddings","grpc","http"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LLukas22.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-21T12:49:55.000Z","updated_at":"2025-01-28T12:50:11.000Z","dependencies_parsed_at":"2024-11-09T01:31:35.555Z","dependency_job_id":null,"html_url":"https://github.com/LLukas22/tei-client","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"15276f5176735aaf8fc7d503f177f009b0e519d3"},"previous_names":["llukas22/tei-client"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLukas22%2Ftei-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLukas22%2Ftei-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLukas22%2Ftei-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LLukas22%2Ftei-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LLukas22","download_url":"https://codeload.github.com/LLukas22/tei-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271925,"owners_count":21075800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","embeddings","grpc","http"],"created_at":"2024-09-24T14:07:26.357Z","updated_at":"2025-10-12T21:05:03.998Z","avatar_url":"https://github.com/LLukas22.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tei-client\n[![PyPI Version](https://img.shields.io/pypi/v/tei-client.svg)](https://pypi.org/project/tei-client)\n[![Supported Python Versions](https://img.shields.io/pypi/pyversions/tei-client.svg)](https://pypi.org/project/tei-client)\n[![example workflow](https://github.com//LLukas22/tei-client/actions/workflows/CI.yml/badge.svg)](https://github.com/LLukas22/tei-client/actions)\n[![coverage](https://raw.githubusercontent.com/LLukas22/tei-client/coverage/badge.svg)](https://github.com/LLukas22/tei-client/blob/coverage/coverage.xml)\n\nConvenience Client for [Hugging Face Text Embeddings Inference (TEI)](https://github.com/huggingface/text-embeddings-inference) with synchronous and asynchronous HTTP/gRPC support.\n\nImplements the API defined in [TEI Swagger](https://huggingface.github.io/text-embeddings-inference/).\n\n## Installation\n\nYou can easily install `tei-client` via pip:\n\n```shell\npip install tei-client\n```\n\n### Grpc Support\nIf you want to use grpc, you need to install `tei-client` with grpc support:\n```shell\npip install tei-client[grpc]\n```\n\n## Usage\n\n## Creating a Client\n\n### HTTP Example\n\nTo create an instance of the client, you can do the following:\n```python\nfrom tei_client import HttpClient\n\nurl = 'http://localhost:8080'\nclient = HttpClient(url)\n```\n\u003cdetails\u003e\n    \u003csummary\u003eExample docker server\u003c/summary\u003e\n\n```shell\ndocker run -p 8080:80 -v ./tei_data:/data ghcr.io/huggingface/text-embeddings-inference:cpu-latest --model-id sentence-transformers/all-MiniLM-L6-v2\n```\n\n\u003c/details\u003e\n\n\n### gRPC Example\n\nAlternatively, you can use gRPC to connect to your server:\n```python\nimport grpc\nfrom tei_client import GrpcClient\n\nchannel = grpc.insecure_channel('localhost:8080')\nclient = GrpcClient(channel)\n```\n\u003cdetails\u003e\n    \u003csummary\u003eExample docker server\u003c/summary\u003e\n\n```shell\ndocker run -p 8080:80 -v ./tei_data:/data ghcr.io/huggingface/text-embeddings-inference:cpu-latest-grpc --model-id sentence-transformers/all-MiniLM-L6-v2\n```\n\n\u003c/details\u003e\n\n## Embedding\n\nTo generate embeddings, you can use the following methods:\n\n#### Single Embedding Generation\n\nYou can generate a single embedding using the `embed` method:\n```python\nresult = client.embed(\"This is an example sentence\")\nprint(result[0])\n```\n\n#### Batch Embedding Generation\n\nTo generate multiple embeddings in batch mode, use the `embed` method with a list of sentences:\n```python\nresults = client.embed([\"This is an example sentence\", \"This is another example sentence\"])\nfor result in results:\n    print(result)\n```\n\n#### Asynchronous Embedding Generation\n\nFor asynchronous embedding generation, you can use the `async_embed` method:\n```python\nresult = await client.async_embed(\"This is an example sentence\")\n```\n\n## Classification\n\nTo generate classification results for a given text, you can use the following methods:\n\n#### Basic Classification\n\nYou can classify a single text using the `classify` method:\n```python\nresult = client.classify(\"This is an example sentence\")\nprint(result[0].scores)\n```\n\n#### NLI Style Classification\n\nFor Natural Language Inference (NLI) style classification, you can use the `classify` method with tuples as input. The first element of the tuple represents the premise and the second element represents the hypothesis.\n\n```python\npremise = \"This is an example sentence\"\nhypothesis = \"An example was given\"\n\nresult = client.classify((premise, hypothesis))\nprint(result[0].scores)\n```\n\n#### Asynchronous and Batched Classification\n\nThe `classify` method also supports batched requests by passing a list of tuples or strings. For asynchronous classification, you can use the `async_classify` method.\n\n```python\n# Classify multiple texts in batch mode\nresults = client.classify([\"This is an example sentence\", \"This is another example sentence\"])\nfor result in results:\n    print(result.scores)\n\n# Asynchronous classification\nresult = await client.async_classify(\"This is an example sentence\")\n```\n\n## Reranking\n\nReranking allows you to refine the order of search results based on additional information. This feature is supported by the `rerank` method.\n\n#### Basic Reranking\n\nYou can use the `rerank` method to rerank search results with the following syntax:\n```python\nresult = client.rerank(\n    query=\"What is Deep Learning?\",  # Search query\n    texts=[\"Lore ipsum\", \"Deep Learning is ...\"]  # List of text snippets\n)\nprint(result)\n```\n#### Asynchronous Reranking\n\nFor asynchronous reranking, use the `async_rerank` method:\n```python\nresult = await client.async_rerank(\n    query=\"What is Deep Learning?\",  # Search query\n    texts=[\"Lore ipsum\", \"Deep Learning is ...\"]  # List of text snippets\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllukas22%2Ftei-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllukas22%2Ftei-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllukas22%2Ftei-client/lists"}