{"id":22883642,"url":"https://github.com/deadbits/vector-embedding-api","last_synced_at":"2025-04-14T21:50:38.490Z","repository":{"id":184098965,"uuid":"671195304","full_name":"deadbits/vector-embedding-api","owner":"deadbits","description":"Flask API for generating text embeddings using OpenAI or sentence_transformers","archived":false,"fork":false,"pushed_at":"2023-09-01T16:47:01.000Z","size":37,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T09:51:32.722Z","etag":null,"topics":["api-server","cache-storage","embedding","huggingface","nlp","openai","sentence-transformers","text-embedding","text-embeddings","vector-embeddings"],"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/deadbits.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2023-07-26T18:59:47.000Z","updated_at":"2024-09-19T03:02:44.000Z","dependencies_parsed_at":"2024-12-13T18:39:42.617Z","dependency_job_id":"00a904f9-77ef-440c-9760-58fac9cd01b3","html_url":"https://github.com/deadbits/vector-embedding-api","commit_stats":null,"previous_names":["deadbits/vector-embedding-api"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deadbits%2Fvector-embedding-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deadbits%2Fvector-embedding-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deadbits%2Fvector-embedding-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deadbits%2Fvector-embedding-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deadbits","download_url":"https://codeload.github.com/deadbits/vector-embedding-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968603,"owners_count":21191156,"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":["api-server","cache-storage","embedding","huggingface","nlp","openai","sentence-transformers","text-embedding","text-embeddings","vector-embeddings"],"created_at":"2024-12-13T18:39:33.745Z","updated_at":"2025-04-14T21:50:38.471Z","avatar_url":"https://github.com/deadbits.png","language":"Python","readme":"# vector-embedding-api\n`vector-embedding-api`provides a Flask API server and client to generate text embeddings using either [OpenAI's embedding model](https://platform.openai.com/docs/guides/embeddings) or the [SentenceTransformers](https://www.sbert.net/) library. The API server now supports in-memory LRU caching for faster retrievals, batch processing for handling multiple texts at once, and a health status endpoint for monitoring the server status.\n\nSentenceTransformers supports over 500 models via [HuggingFace Hub](https://huggingface.co/sentence-transformers).\n\n## Features 🎯\n* POST endpoint to create text embeddings\n  * sentence_transformers\n  * OpenAI text-embedding-ada-002\n* In-memory LRU cache for quick retrieval of embeddings\n* Batch processing to handle multiple texts in a single request\n* Easy setup with configuration file\n* Health status endpoint\n* Python client utility for submitting text or files\n\n### Installation 💻\nTo run this server locally, follow the steps below:\n\n**Clone the repository:** 📦\n```bash\ngit clone https://github.com/deadbits/vector-embedding-api.git\ncd vector-embedding-api\n```\n\n**Set up a virtual environment (optional but recommended):** 🐍\n```bash\nvirtualenv -p /usr/bin/python3.10 venv\nsource venv/bin/activate\n```\n\n**Install the required dependencies:** 🛠️\n```bash\npip install -r requirements.txt\n```\n\n### Usage\n\n**Modify the [server.conf](/server.conf) configuration file:** ⚙️\n```ini\n[main]\nopenai_api_key = YOUR_OPENAI_API_KEY\nsent_transformers_model = sentence-transformers/all-MiniLM-L6-v2\nuse_cache = true/false\n```\n\n**Start the server:** 🚀\n```\npython server.py\n```\n\nThe server should now be running on http://127.0.0.1:5000/.\n\n### API Endpoints 🌐\n##### Client Usage\nA small [Python client](/client.py) is provided to assist with submitting text strings or files. \n\n**Usage**\n`python3 client.py -t \"Your text here\" -m local`\n\n`python3 client.py -f /path/to/yourfile.txt -m openai`\n\n#### POST /submit\nSubmits an individual text string or a list of text strings for embedding generation.\n\n**Request Parameters**\n\n* **text:** The text string or list of text strings to generate the embedding for. (Required)\n* **model:** Type of model to be used, either local for SentenceTransformer models or openai for OpenAI's model. Default is local.\n\n**Response**\n\n* **embedding:** The generated embedding array.\n* **status:** Status of the request, either success or error.\n* **elapsed:** The elapsed time taken for generating the embedding (in milliseconds).\n* **model:** The model used to generate the embedding.\n* **cache:** Boolean indicating if the result was retrieved from cache. (Optional)\n* **message:** Error message if the status is error. (Optional)\n\n#### GET /health\nChecks the server's health status.\n\n**Response**\n\n* **cache.enabled:** Boolean indicating status of the cache\n* **cache.max_size:** Maximum cache size\n* **cache.size:** Current cache size\n* **models.openai:** Boolean indicating if OpenAI embeddings are enabled. (Optional)\n* **models.sentence-transformers:** Name of sentence-transformers model in use.\n\n```json\n{\n  \"cache\": {\n    \"enabled\": true,\n    \"max_size\": 500,\n    \"size\": 0\n  },\n  \"models\": {\n    \"openai\": true,\n    \"sentence-transformers\": \"sentence-transformers/all-MiniLM-L6-v2\"\n  }\n}\n```\n\n#### Example Usage\nSend a POST request to the /submit endpoint with JSON payload:\n\n```json\n{\n    \"text\": \"Your text here\",\n    \"model\": \"local\"\n}\n\n// multi text submission\n{\n    \"text\": [\"Text1 goes here\", \"Text2 goes here\"], \n    \"model\": \"openai\"\n}\n```\n\nYou'll receive a response containing the embedding and additional information:\n\n```json\n[\n  {\n    \"embedding\": [...],\n    \"status\": \"success\",\n    \"elapsed\": 123,\n    \"model\": \"sentence-transformers/all-MiniLM-L6-v2\"\n  }\n]\n\n[\n  {\n    \"embedding\": [...],\n    \"status\": \"success\",\n    \"elapsed\": 123,\n    \"model\": \"openai\"\n  }, \n  {\n    \"embedding\": [...],\n    \"status\": \"success\",\n    \"elapsed\": 123,\n    \"model\": \"openai\"\n  }, \n]\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeadbits%2Fvector-embedding-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeadbits%2Fvector-embedding-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeadbits%2Fvector-embedding-api/lists"}