English · 中文
LLM Embedding tool HTTP service
- Support Vector Database: Chroma
- Support file type: pure text, include
Markdown
,TXT
- HTTP API Wrapper of Dart List Embeddings
- Base on Lite Embeddings Dart的EmbeddingsService(DTO included), add Controller、Router, wrapper to HTTP/WS API.
- Docs file, according to
/example/docs/*.md
Separator
in the file- If
markdown
file, recommend to use<!--SEPARATOR-->
as separator, for NOT show it inmarkdown
after rendering
- If
- Add
.env
file in theexample
folder, and add below content in the.env
file:baseUrl = https://xxx.xxx.com # LLM API BaseURL apiKey = sk-xxxxxxxxxxxxxxxxxxxx # LLM API ApiKey
debug
orrun
mode run/bin/server.dart
filemain()
- Docs CRUD API, include:
- /version: get version number, to confirm server running
- /init: post the llm config to initial the embeddings service
- /docs/create-by-text: Create docs embeddings, post whole text and separator, service will split and write to vector database
- /docs/create: Create docs embeddings, post the split docs, service will write to vector database
- /docs/delete: Delete docs, post docsId
- /docs/list: List all docs, return docsId and docsName Array
- /docs/rename: Rename docsName
- /docs/query: Text query, return N segment array with distance sort
- /docs/batch-query: Text array query, query multi text at once, return N segment array in array
- /docs/multi-query: Docs array query, query multi docs with one text, return N segment with docsId array
- /segment/list: List all segments in the docs
- /segment/insert: Insert segment by index. If not index, new segment will be inserted at last
- /segment/update: Update segment
- /segment/delete: Delete segment
- /dispose: Dispose vector database connection
http://127.0.0.1:9537/api
-
Feature: get version number, to confirm server running
-
Request params: null
-
Response body sample:
{ "version": "0.1.0" }
-
Feature: post the llm config to initial the embeddings service
-
Request params:
- LLM config: baseUrl, apiKey, model
- Sample:
{ "baseUrl": "<LLM API baseUrl, e.g. https://api.openai.com/v1>>", "apiKey": "<LLM API apiKey, e.g. sk-xxxxxxxxxx>", "model": "<LLM API embeddings model name, e.g. : text-embedding-ada-002>" }
-
Response body:
- Echo init info, include vectorDatabase name, baseUrl, embeddingsModel
- Response body sample
{ "vectorDatabase": "<Vector Database name, e.g. : chroma>", "baseUrl": "<LLM API baseUrl, e.g. https://api.openai.com/v1>>", "embeddingsModel": "<LLM API embeddings model name, e.g. : text-embedding-ada-002>" }
- Feature: Create docs embeddings, post whole text and separator, service will split and write to vector database
- Request params:
- Docs info: docsName, text, separator, metadata
- Sample
{ "docsName": "<Docs name, e.g. Moore's Law for Everything.md>", "text": "<Docs full text, with separetor>", "separator": "<Separator text>", "metadata": "<json map, value only int, float, string, bool, NOT support object and array. Each segment with same metadata>" }
- Response body:
- Create successful docs info: docsId, docsName
- Response body sample
{ "docsId": "<Docs Id>", "docsName": "<Docs Name>" }
- Feature: Create docs embeddings, post the split docs, service will write to vector database
- Request params:
- Docs info: docsName, segment and metadata array
- Sample
{ "docsName": "<Docs name, e.g. Moore's Law for Everything.md>", "segmentList": [ { "text": "<Segment text>", "metadata": "<json map, value only int, float, string, bool, NOT support object and array>" } ] }
- Response body:
- Create successful docs info: docsId, docsName
- Response body sample
{ "docsId": "<Docs Id>", "docsName": "<Docs Name>" }
- Feature: Delete docs, post docsId
- Request params:
- DocsId
- Sample
{ "docsId": "xxxxxxxx" }
- Response body:
- Docs be deleted info: docsId
- Response body sample
{ "docsId": "xxxxxxxx" }
- Feature: List all docs, return docsId and docsName Array
- Request params: null
- Response body:
- Docs info list: docsId and docsName
- Response body sample
[ { "docsId": "<Docs Id>", "docsName": "<Docs Name>" } ]
- Feature: Rename docsName
- Request params:
- docsId, new docsName
- Sample
{ "docsId": "<Docs Id>", "docsName": "<Docs Name>" }
- Response body:
- Docs be modified info: docsId and docsName
- Response body sample
{ "docsId": "<Docs Id>", "docsName": "<Docs Name>" }
- Feature: Text query, return N segment array with distance sort
- Request params:
- docsId, queryText, return query result count
- Sample
{ "docsId": "xxxxxxxx", "queryText": "<query text string>", "nResults": "<UInt, return query result by sort number>" }
- Response body:
- docsId, segmentResultList
- Response body sample
{ "docsId": "xxxxxxxx", "segmentResultList": [ { "segmentId": "<Segment Id>", "text": "<Segment text>", "metadata": "<json map, segment with>", "distance": "<0.x float, segment match distance, smaller means closer>" } ] }
-
Feature: Text array query, query multi text at once, return N segment array in array
-
Request params:
- docsId, queryText array, return query result count
- Sample
{ "docsId": "xxxxxxxx", "queryTextList": [ "<Query Text 1>", "<Query Text 2>" ], "nResults": "<UInt, return query result by sort number>" }
-
Response body:
- Query result: docsId and segmentResultList array
- Response body sample
[ { "docsId": "xxxxxxxx", "segmentResultList": [ { "segmentId": "<Segment Id>", "text": "<Segment text>", "metadata": "<json map, segment with>", "distance": "<0.x float, segment match distance, smaller means closer>" } ] } ]
-
/docs/multi-query
:
- Feature: Docs array query, query multi docs with one text, return N segment with docsId array
- Request params:
- docsId array, queryText, return query result count
- Sample
{ "docsIdList": ["xxxxxxxx", "yyyyyyyy"], "queryText": "<Query Text 1>", "nResults": "<UInt, return query result by sort number>", "removeDuplicates": "<(Optional)boolean, default:true, return segments will be removed if same text>" }
- Response body:
- Query result: segment info array, include docsId, segmentId, segment text, metadata, distance
- Response body sample
[ { "docsId": "xxxxxxxx", "segmentId": "<Segment Id>", "text": "<Segment text>", "metadata": "<json map, segment with>", "distance": "<0.x float, segment match distance, smaller means closer>" } ]
- Feature: List all segments in the docs
- Request params:
- docsId
- Sample
{ "docsId": "xxxxxxxx" }
- Response body:
- docsId, docsName, segment info list
- Response body sample
{ "docsId": "xxxxxxxx", "docsName": "<Docs Name>", "segmentInfoList": [ { "SegmentId": "<Segment Id>", "text": "<Segment text>", "metadata": "<json map, segment with>" } ] }
- Feature: Insert segment by index. If not index, new segment will be inserted at last
- Request params:
- docsId, new segment, index
- Sample
{ "docsId": "xxxxxxxx", "segment": { "text": "<Segment text>", "metadata": "<json map, segment with>" }, "index": "(Optional) UInt, if null or large than length, be inserted at last" }
- Response body:
- new Segment ID
- Response body sample
{ "segmentId": "xxxxxxxx" }
- Feature: Update segment
- Request params:
- docsId, segment
- Sample
{ "docsId": "xxxxxxxx", "segment": { "segmentId": "Segment Id", "text": "<Segment text>", "metadata": "<json map, segment with>" } }
- Response body:
- Segment Id
- Response body sample
{ "segmentId": "xxxxxxxx" }
- Feature: Delete segment
- Request params:
- Segment be deleted docsId and segmentId
- Sample
{ "docsId": "xxxxxxxx", "segmentId": "xxxxxxxx" }
- Response body:
- Segment Id
- Response body sample
{ "segmentId": "xxxxxxxx" }
- Feature: Dispose vector database connection
- Request params:
- Response body:
- Dispose successfully text
- Response body sample
"Dispose successfully."
- Build in shell script:
dart compile exe bin/server.dart -o build/lite_embeddings_dart_server
- Then the
lite_embeddings_dart_server
file will be inbuild
folder - Copy
config.json
file tolite_embeddings_dart_server
same folder - Run in shell script:
./lite_embeddings_dart_server
- Terminal will show:
INFO: 2024-06-24 14:48:05.862057: PID 34567: [HTTP] Start Server - http://0.0.0.0:9537/api
- After server running, will create
log
folder andembeddings.log
file in the folder, to record server running logs.