barrel_embed_port_server (barrel_embed v2.3.0)

View Source

Async Python port server with request multiplexing

A gen_server that manages communication with a Python embedding server. Supports concurrent requests by tracking request IDs and routing responses back to the correct callers.

Usage

   %% Start the server
   {ok, Server} = barrel_embed_port_server:start_link(Python, Args, Opts).
  
   %% Make concurrent embedding requests
   spawn(fun() -> barrel_embed_port_server:embed_batch(Server, Texts1, 60000) end).
   spawn(fun() -> barrel_embed_port_server:embed_batch(Server, Texts2, 60000) end).
  
   %% Stop when done
   barrel_embed_port_server:stop(Server).

Request Multiplexing

Multiple Erlang processes can call embed_batch/3 concurrently. Each request is assigned a unique ID and sent to Python. The Python server includes the ID in its response, allowing this gen_server to route responses to the correct waiting callers.

Summary

Functions

Generate embeddings for texts.

Generate embeddings for images (base64 encoded).

Generate multi-vector embeddings.

Generate sparse embeddings.

Get model info.

Start the port server. Args are passed to python -m barrel_embed.

Stop the server and close the port.

Functions

embed_batch(Server, Texts, Timeout)

-spec embed_batch(pid(), [binary()], timeout()) -> {ok, [[float()]]} | {error, term()}.

Generate embeddings for texts.

embed_image_batch(Server, Images, Timeout)

-spec embed_image_batch(pid(), [binary()], timeout()) -> {ok, [[float()]]} | {error, term()}.

Generate embeddings for images (base64 encoded).

embed_multi_batch(Server, Texts, Timeout)

-spec embed_multi_batch(pid(), [binary()], timeout()) -> {ok, [[[float()]]]} | {error, term()}.

Generate multi-vector embeddings.

embed_sparse_batch(Server, Texts, Timeout)

-spec embed_sparse_batch(pid(), [binary()], timeout()) -> {ok, [map()]} | {error, term()}.

Generate sparse embeddings.

handle_call(_, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

info(Server, Timeout)

-spec info(pid(), timeout()) -> {ok, map()} | {error, term()}.

Get model info.

init(_)

start_link(Python, Args, Opts)

-spec start_link(string(), [string()], proplists:proplist()) -> {ok, pid()} | {error, term()}.

Start the port server. Args are passed to python -m barrel_embed.

stop(Server)

-spec stop(pid()) -> ok.

Stop the server and close the port.

terminate(Reason, State)