import os
import avenieca
from avenieca.api.eca import ECA
from avenieca.api.model import Config, EmbeddingInputInsert, EmbeddingInputHash
# Initialize client
config = Config(
uri="http://localhost:2580/v1",
username=os.getenv("USERNAME"),
password=os.getenv("PASSWORD")
)
eca = ECA(config)
# Define secret for hashing
SECRET = "my_secret_key"
# Create embedding input
input_text = "temperature: 25 degrees"
input_hash = avenieca.encode(SECRET, input_text)
embedding = EmbeddingInputInsert(
module_id="air_conditioner",
input=input_text,
hash=input_hash
)
res, status = eca.embedding.create(data=embedding)
if status == 201:
emb_id = res.id
print(f"Created embedding {emb_id}")
# Retrieve by ID
res, status = eca.embedding.get_one(
module_id="air_conditioner",
db_id=emb_id
)
print(f"Retrieved: {res.input}")
# Retrieve by hash
hash_query = EmbeddingInputHash(hash=input_hash)
res, status = eca.embedding.get_one_with_hash(
module_id="air_conditioner",
data=hash_query
)
print(f"Found by hash: {res.input}")
# Get all for module
res, status = eca.embedding.get_all(module_id="air_conditioner")
print(f"Total embeddings: {len(res)}")