simplevecdb.embeddings.models
load_model(repo_id)
Load (and cache on disk) a SentenceTransformer for the given repo id.
The repo_id is validated against the canonical HuggingFace format
before being passed to snapshot_download/SentenceTransformer;
this prevents path-traversal style inputs and local filesystem paths.
trust_remote_code is forced off so a malicious model card cannot
execute arbitrary code on load.
Source code in src/simplevecdb/embeddings/models.py
get_embedder(model_id=None)
Return a cached embedder for the requested model (defaults to config value).
Source code in src/simplevecdb/embeddings/models.py
embed_texts(texts, *, model_id=None, batch_size=None)
Embed a list of texts using the default model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
texts
|
list[str]
|
List of strings to embed. |
required |
model_id
|
str | None
|
Optional repo id / alias override. |
None
|
batch_size
|
int | None
|
Optional override for encode batch size. |
None
|
Returns:
| Type | Description |
|---|---|
list[list[float]]
|
List of embedding vectors (list of floats). |
Source code in src/simplevecdb/embeddings/models.py
simplevecdb.embeddings.server
RateLimiter
Token bucket rate limiter per IP/identity with TTL cleanup.
Source code in src/simplevecdb/embeddings/server.py
is_allowed(identity)
Check if request is allowed and consume a token.
Source code in src/simplevecdb/embeddings/server.py
ModelRegistry
In-memory mapping of allowed embedding models.
Source code in src/simplevecdb/embeddings/server.py
resolve(requested)
Return (display_id, repo_id) for a requested alias/model name.
Source code in src/simplevecdb/embeddings/server.py
list_models()
Return OpenAI-compatible model listings.
Source code in src/simplevecdb/embeddings/server.py
UsageMeter
Minimal in-memory tracker for request usage statistics.
Source code in src/simplevecdb/embeddings/server.py
snapshot(identity=None, *, aggregate=False)
Return per-identity usage stats, or an aggregate total.
When identity is given, return only that bucket. Otherwise:
- aggregate=False (default): the full per-identity map.
- aggregate=True: a single {"_total": {...}} bucket
summed across identities. The aggregate mode is what the
/v1/usage endpoint exposes when auth is disabled, so the
server doesn't leak the list of client IPs that have used it.
Source code in src/simplevecdb/embeddings/server.py
health_check()
async
authenticate_request(credentials=Security(auth_scheme), api_key_header=Header(default=None, alias='X-API-Key'))
Validate API key if auth is enabled; otherwise return anonymous identity.
Source code in src/simplevecdb/embeddings/server.py
create_embeddings(request, raw_request, api_identity=Depends(authenticate_request))
async
Create embeddings for the input text(s).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
EmbeddingRequest
|
EmbeddingRequest containing input text and model. |
required |
Returns:
| Type | Description |
|---|---|
EmbeddingResponse
|
EmbeddingResponse with vector data. |
Source code in src/simplevecdb/embeddings/server.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
list_models(api_identity=Depends(authenticate_request))
async
List available embedding models (requires auth when configured).
Source code in src/simplevecdb/embeddings/server.py
usage(api_identity=Depends(authenticate_request))
async
Return aggregate or per-key usage statistics.
When auth is configured, return only the caller's bucket. When auth is disabled, return a single aggregated total — the per-identity buckets are keyed by client IP and exposing the full list to anyone is an information leak.
Source code in src/simplevecdb/embeddings/server.py
run_server(host=None, port=None)
Run the embedding server.
Can be called programmatically or via the simplevecdb-server CLI.
Examples
Run with default settings::
$ simplevecdb-server
Override host and port::
$ simplevecdb-server --host 0.0.0.0 --port 9000
Skip model warm-up::
$ simplevecdb-server --no-warmup
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str | None
|
Server host (defaults to config.SERVER_HOST). |
None
|
port
|
int | None
|
Server port (defaults to config.SERVER_PORT). |
None
|
Source code in src/simplevecdb/embeddings/server.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | |