port 9050 ; HF_TOKEN env needed - huggin face token; API_TOKEN - secure api token
1.4K
With Python, HuggingFace and MongoDB Atlas.
flask run --host=0.0.0.0 --port=9050
Requirements, dreams & desires: I am at the stage of building my MSC Advanced Computing project. It is distributed app for education with some whistles, fountains and pretty flowers (but not really). I wanted to create Question/Post suggesting system. I could build that bases on Question/Post (Q/P) tags, but that isn't very accurate, modern and hot. I wanted to use my (still poor) existing NLP skills and use something much modern that SQL query to find Questions/Posts by tags.
Solution (?) : Well ... I ended up (by now) with an attempt of using word embeddings and vector search to find related Q/P.
How it works (or how it should work): On the UI side of adding a Q/P, when
one is being added the user has to type Q/P title (summary) and then he
goes to the body of the question. The Q/P title is being sent (in the background)
to this API here to the '/embedding/search endpoint. This endpoint creates
the Q/P title embedding and searches for similar ones in the MongoDB created for
this purpose.
Other possibilities:
/embedding endpoint just to get the embeddings/embedding/mongostore endpoint to store it's embedding in MongoDBIndex Name: QuestionSematicSearchIndex
Pick the correct db and collection and set the index JSON as below:
{ "mappings": { "dynamic": true, "fields": { "question_embedding": { "dimensions": 384, "similarity": "dotProduct", "type": "knnVector" } } } }
Create .env file. This file will hold all environment variables required
for docker-compose.yml file.
It should contain below variables:
# Env variables for docker-compose
HF_TOKEN=
API_TOKEN=
MONDO_CONN_STRING=
SEARCH_LIMITS_COUNT=
HF_TOKEN - HuggingFace token (I got one but free version allow to make few FREE embeddings)API_TOKEN - token to secure api. One is set when running the Docker container based on the image.
Create your own and set and docker image env.var or env var in your system if you're running
app manually. Example: export API_TOKEN=hf_myHaPpYToKeNgOesHeRe or set API_TOKEN=hf_myHaPpYToKeNgOesHeRe
Same should be done for HF_TOKEN.SEARCH_LIMITS_COUNT - how many MongDB records should be displayed in '/embedding/search' results'When making the API request , set header x-access-tokens to match your
API_TOKEN.
.env file . For Hugging Face token, make a free account, go
to Your Profile -> Settings -> Access Tokens -> New Tokendocker compose up -d (you must have Docker and Compose in your system)Content type
Image
Digest
sha256:77d78a4e3…
Size
2.8 GB
Last updated
about 2 years ago
docker pull sever3d/hugginface-embedding-api