Skip to main content

embedding-provider

Embedding Provier

Queries to the Milvus datasource in the Engine Server require the query to be embedded first.

An HTTP protocol-based Embedding Server can be configured as the Embedding Provider.

# milvus data source
[[database]]
name = "vec"
engine = "milvus"
[database.config]
endpoint = "localhost:19530"
dail_timeout = "3s"
[database.rate_limit]
max_qps=1
# embedding provider config
[[database.config.embedding_provider]]
name="paraphrase-albert-small-v2"
endpoint="http://127.0.0.1:5000/embeddings"
timeout = "3s"
default=true

Simple example of an Embedding Server:

from flask import Flask, request, jsonify
from pymilvus import model

app = Flask(__name__)

model_name = "paraphrase-albert-small-v2"
embedding_fn = model.DefaultEmbeddingFunction()

def encode(docs):
return embedding_fn.encode_documents(docs)

@app.route('/embeddings', methods=['POST'])
def get_embeddings():
data = request.json
input_text = data.get('input')

if not input_text:
return jsonify({"error": "input is required"}), 400

embeddings = encode([input_text])
response = {
'object':'list',
'model':model_name,
'data':[
{
'object':'embedding',
'embedding':embeddings[0].tolist(),
'index':0
}
]
}
return jsonify(response)

if __name__ == '__main__':
app.run(debug=True)

For more Embedding Model usage references.