Skip to main content

Easy Embed App

Simple self-hosted semantic search API.

GitHub: https://github.com/rafaelolal/csci-3485-final

Demo: https://github.com/rafaelolal/csci-3485-final/blob/main/CSCI_3485_Final_Project_Presentation.pptx

Installation

pip install easy-embed-rafaelolal

Usage

from easy_embed import App

app = App()

# Optional: set a SentenceTransformer model by passing in whatever necessary
# arguments
# app.set_model(**kwargs)
# 
# Optional: set device
# app.set_model_device(my_device)
#
# Optional: models that require further setup before being used can be
# accessed through `app.model`
# app.model.prepare()
#
# Optional: for models with unique encoding functions, you can override
# `app.encode` with `custom_encode` using default parameters and custom logic
# app.encode = lambda text, new = "hi": app.model.transform(text, new)

app.run(host="0.0.0.0", port=8000, allow_origins=["*"])

Documentation

API Endpoints

Visit the /docs url for more information and for quick testing.

Below are example values for the response body:

/create

{
  "doc": "string",
  "index": 0,
  "collection": "string"
}

/read

Use the below values only for small and simple semantic search tasks. Consider using the collection value for more documents or more frequent needs.

{
  "q": "string",
  "docs": [
    "string"
  ],
  "k": 0
}

Use the below values if you have already used the create endpoint to precompute the embedding vectors of the documents.

{
  "q": "string",
  "collection": "string",
  "k": 0
}

/update

The main purpose of this endpoint is to keep the embeddings up to date with your data. Consider creating a custom script to automatically make a call to this endpoint whenever a datapoint is edited in your database.

{
  "index": 0,
  "collection": "string",
  "doc": "string"
}

/delete

{
  "index": 0,
  "collection": "string"
}

Custom Embedding Model

Important note: the return type for a custom encode function must be -> list[float] | list[list[float]]. This is because of how the similarities are computed.

Refer to the usage example above.

Main Dependencies

Python version: python==3.12.8

fastapi==0.115.6
sentence-transformers==3.3.1
sqlmodel==0.0.22

Citations

How to publish to PyPi: https://youtu.be/5KEObONUkik

Default model used: Solatorio, Aivin V. "GISTEmbed: Guided In-sample Selection of Training Negatives for Text Embedding Fine-tuning." arXiv preprint arXiv:2402.16829 (2024).

Release files for easy-embed-rafaelolal 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for easy-embed-rafaelolal 1.0.0
File Size Uploaded
easy_embed_rafaelolal-1.0.0.tar.gz 9.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for easy-embed-rafaelolal 1.0.0
File Interpreter ABI Platform
easy_embed_rafaelolal-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.5 kB

Release files / easy_embed_rafaelolal-1.0.0.tar.gz

Download URL easy_embed_rafaelolal-1.0.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e8bd4e515db7eb17a0a34992cbed24c94a54207fe0132e8ad16ded1af2eea1ad
BLAKE2b-256 checksum
How to use checksums
a38f05be81225079580bc317b7938ba7a30bcd7c3bec07330577fccd44492f5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release files / easy_embed_rafaelolal-1.0.0-py3-none-any.whl

Download URL easy_embed_rafaelolal-1.0.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
128e08539266252111958de7fa147a1c0bc58d2424e4b6881c07fe08657def72
BLAKE2b-256 checksum
How to use checksums
83ea95b09cffa8568a8de624d6ebe4f63eb093b8662e8310e8ff908694443a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page