Embeddings/vectors are numerical representations of complex data like text or images in a format that machines can process. Embedding models convert text, images, audios, and videos into vectors of real numbers. This process captures semantic meaning, allowing algorithms to understand content similarity and context. This technique is pivotal in various applications, from Retrieval Augmented Generation (RAG) to recommendation systems to language translation, as it enables computers to 'understand' and work with human language.
In embedding models, the mathematical premise is that the closer two vectors are in high-dimensional space, the more semantically similar they are. This characteristic is leveraged in vector databases for semantic similarity search, using algorithms like nearest neighbor search. These algorithms compute the distances between vectors, interpreting smaller distances as higher similarity. This approach enables applications to find closely related items (like texts, images, audios, videos) based on their embedded vector representations, making it possible to conduct searches and analyses based on the meaning and context of the data, rather than just literal matches.
Use Embeddings
Starting in v0.3, Epsilla supports automatically embed your documents and questions within the vector database, which significantly simplify the end to end semantic similarity search workflow.
When creating tables, you can define indices to let Epsilla automatically create embeddings for the STRING fields:
You can omit the model when defining indices, and Epsilla uses BAAI/bge-small-en-v1.5 by default.
Then you can insert records in their raw format and let Epsilla handle the embedding:
status_code, response = db.insert(
table_name="MyTable",
records=[
{"ID": 1, "Doc": "The garden was blooming with vibrant flowers, attracting butterflies and bees with their sweet nectar.", "Embedding": [0.05, 0.61, 0.76, 0.74]},
{"ID": 2, "Doc": "In the busy city streets, people rushed to and fro, hardly noticing the beauty of the day.", "Embedding": [0.19, 0.81, 0.75, 0.11]},
{"ID": 3, "Doc": "The library was a quiet haven, filled with the scent of old books and the soft rustling of pages.", "Embedding": [0.36, 0.55, 0.47, 0.94]},
{"ID": 4, "Doc": "High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below.", "Embedding": [0.18, 0.01, 0.85, 0.80]},
{"ID": 5, "Doc": "At the beach, children played joyfully in the sand, building castles and chasing the waves.", "Embedding": [0.24, 0.18, 0.22, 0.44]}
]
)
await db.insert('MyTable',
[
{"ID": 1, "Doc": "The garden was blooming with vibrant flowers, attracting butterflies and bees with their sweet nectar.", "Embedding": [0.05, 0.61, 0.76, 0.74]},
{"ID": 2, "Doc": "In the busy city streets, people rushed to and fro, hardly noticing the beauty of the day.", "Embedding": [0.19, 0.81, 0.75, 0.11]},
{"ID": 3, "Doc": "The library was a quiet haven, filled with the scent of old books and the soft rustling of pages.", "Embedding": [0.36, 0.55, 0.47, 0.94]},
{"ID": 4, "Doc": "High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below.", "Embedding": [0.18, 0.01, 0.85, 0.80]},
{"ID": 5, "Doc": "At the beach, children played joyfully in the sand, building castles and chasing the waves.", "Embedding": [0.24, 0.18, 0.22, 0.44]}
]
);
After inserting records, you can query the table with natural language questions:
status_code, response = db.query(
table_name="MyTable",
query_text="Where can I find a serene environment, ideal for relaxation and introspection?",
limit=2
)
print(response)
Output
{
'message': 'Query search successfully.',
'result': [
{'Doc': 'The library was a quiet haven, filled with the scent of old books and the soft rustling of pages.', 'ID': 3},
{'Doc': 'High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below.', 'ID': 4}
],
'statusCode': 200
}
// search
const query = await db.query(
'MyTable',
{
query: "Where can I find a serene environment, ideal for relaxation and introspection?",
limit: 2
}
);
console.log(JSON.stringify(query));
Output:
{
"statusCode":200,
"message":"Query search successfully.",
"result":[
{"Doc": "The library was a quiet haven, filled with the scent of old books and the soft rustling of pages.", "ID": 3},
{"Doc": "High in the mountains, the air was crisp and clear, revealing breathtaking views of the valley below.", "ID": 4}
]
}
Built-in Embeddings
Here is the list of built-in embedding models Epsilla supports:
BAAI/bge-small-en
BAAI/bge-small-en-v1.5
BAAI/bge-small-zh-v1.5
BAAI/bge-base-en
BAAI/bge-base-en-v1.5
sentence-transformers/all-MiniLM-L6-v2
BAAI/bge-small-en-v1.5 and sentence-transformers/all-MiniLM-L6-v2 are enabled by default. You can turn on other models via docker run command environment variable EMBEDDING_MODELS (using comma separated string):
docker run --pull=always -d -p 8888:8888 -e EMBEDDING_MODELS="BAAI/bge-small-zh-v1.5,BAAI/bge-base-en" epsilla/vectordb
When using these built-in embedding models, the embedding are conducted within your local laptop without outbound network. They use CPU first to do the embedding. So make sure you have enough CPU power and memory to handle the models before enabling them.
OpenAI Embedding
Epsilla supports these OpenAI embedding models:
Name
Dimensions
Support Dimension Reduction
openai/text-embedding-3-large
3072
Yes
openai/text-embedding-3-small
1536
Yes
openai/text-embedding-ada-002
1536
No
When using OpenAI embedding on Docker, make sure provide the X-OpenAI-API-Key header when connecting to the vector database:
db = vectordb.Client(
...
headers={
"X-OpenAI-API-Key": <Your OpenAI API key here>
}
)
const db = new epsillajs.EpsillaDB({
...
headers: {
"X-OpenAI-API-Key": <Your OpenAI API key here>
}
});
If you are using Epsilla Cloud, make sure to add OpenAI integration instead of passing the header.
And use the embedding model when defining the index: