Skip to content

Commit 07871ce

Browse files
committed
updated /submit endpoint, added cache, add client docs
1 parent f5bb8ae commit 07871ce

File tree

1 file changed

+44
-19
lines changed

1 file changed

+44
-19
lines changed

README.md

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# vector-embedding-api
2-
Flask API server for generating text embeddings using [OpenAI's embedding model](https://platform.openai.com/docs/guides/embeddings) or the [SentenceTransformers](https://www.sbert.net/) library. SentenceTransformers supports over 500 models via [HuggingFace Hub](https://huggingface.co/sentence-transformers).
2+
`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 also offers an in-memory cache for embeddings and returns results from the cache when available.
3+
4+
SentenceTransformers supports over 500 models via [HuggingFace Hub](https://huggingface.co/sentence-transformers).
35

46
## Features 🎯
5-
* POST endpoint to create text embedding models
7+
* POST endpoint to create text embeddings
68
* sentence_transformers
7-
* OpenAI text-embedding-ada-002
9+
* OpenAI text-embedding-ada-002
10+
* In-memory cache for embeddings
811
* Easy setup with configuration file
912
* Simple integration with other applications
1013
* Python client utility for submitting text
@@ -15,12 +18,12 @@ To run this server locally, follow the steps below:
1518
**Clone the repository:** 📦
1619
```bash
1720
git clone https://github.com/deadbits/vector-embedding-api.git
18-
cd text-embeddings-server
21+
cd vector-embedding-api
1922
```
2023

2124
**Set up a virtual environment (optional but recommended):** 🐍
2225
```bash
23-
python3 -m venv venv
26+
virtualenv -p /usr/bin/python3.10 venv
2427
source venv/bin/activate
2528
```
2629

@@ -30,13 +33,14 @@ pip install -r requirements.txt
3033
```
3134

3235
### Usage
33-
Before running the server, make sure you have obtained an API key from OpenAI to use their model. You also need to set the SentenceTransformers model you want to use in the [server.conf](/server.conf) file.
36+
Modify the [server.conf](/server.conf) file to specify a SentenceTransformers model, your OpenAI API key, or both.
3437

3538
**Modify the server.conf configuration file:** ⚙️
3639
```ini
3740
[main]
3841
openai_api_key = YOUR_OPENAI_API_KEY
3942
sent_transformers_model = sentence-transformers/all-MiniLM-L6-v2
43+
use_cache = true/false
4044
```
4145

4246
**Start the server:** 🚀
@@ -46,28 +50,49 @@ python server.py
4650

4751
The server should now be running on http://127.0.0.1:5000/.
4852

49-
5053
### API Endpoints 🌐
54+
##### Client Usage
55+
A small [Python client](/client.py) is provided to assist with submitting text strings or text files.
56+
57+
**Usage**
58+
`python3 client.py -t "Your text here" -m local`
59+
60+
`python3 client.py -f /path/to/yourfile.txt -m openai`
5161

5262
#### POST /submit
53-
Submit text to be converted to embeddings.
54-
The sentence transformers model will be used by default, but you can change the "model" field to "openai" to use `text-embedding-ada-002`.
63+
Submits a text string for embedding generation.
5564

56-
**POST data:**
57-
`{"text": 'Put your text here', "model": "local"}`
58-
`{"text": 'Put your text here', "model": "openai"}`
65+
**Request Parameters**
5966

60-
The default is to use the SentenceTransformers model.
67+
* **text:** The text string to generate the embedding for. (Required)
68+
* **model:** Type of model to be used, either local for SentenceTransformer models or openai for OpenAI's model. Default is local.
6169

62-
**Example Request:**
63-
```bash
64-
curl -X POST -H "Content-Type: application/json" -d '{"text": 'Put your text here', "model": "local"}' http://127.0.0.1:5000/submit
70+
**Response**
71+
72+
* **embedding:** The generated embedding array.
73+
* **status:** Status of the request, either success or error.
74+
* **elapsed:** The elapsed time taken for generating the embedding (in milliseconds).
75+
* **model:** The model used to generate the embedding.
76+
* **cache:** Boolean indicating if the result was retrieved from cache. (Optional)
77+
* **message:** Error message if the status is error. (Optional)
78+
79+
#### Example Usage
80+
Send a POST request to the /submit endpoint with JSON payload:
81+
82+
```json
83+
{
84+
"text": "Your text here",
85+
"model": "local"
86+
}
6587
```
6688

67-
**Example Response:**
89+
You'll receive a response containing the embedding and additional information:
90+
6891
```json
6992
{
70-
"embedding": [0.123, 0.456, ..., 0.789],
71-
"status": "success"
93+
"embedding": [...],
94+
"status": "success",
95+
"elapsed": 293.52,
96+
"model": "sentence-transformers/all-MiniLM-L6-v2"
7297
}
7398
```

0 commit comments

Comments
 (0)