import os
from avenieca.api.eca import ECA
from avenieca.api.model import Config, DocumentInsert, RetrievalRequest
# Initialize client
config = Config(
uri="http://localhost:2580/v1",
username=os.getenv("USERNAME"),
password=os.getenv("PASSWORD")
)
eca = ECA(config)
# First, create and embed some documents
documents = [
DocumentInsert(
doc_id="weather_001",
text="The temperature on May 3rd at 1pm was 28 degrees Celsius.",
embed=True
),
DocumentInsert(
doc_id="weather_002",
text="On May 3rd at 2pm, the temperature dropped to 25 degrees.",
embed=True
),
DocumentInsert(
doc_id="weather_003",
text="May 4th saw temperatures of 30 degrees at noon.",
embed=True
)
]
for doc in documents:
res, status = eca.document.create(data=doc)
print(f"Created document: {res.doc_id}")
# Now query the documents
retrieval = RetrievalRequest(
query="what is the temperature on 3rd of may at around 1pm?"
)
res, status = eca.retrieval.query(data=retrieval)
if status == 200:
print(f"\nQuery: {retrieval.query}")
print(f"Response: {res.response}")
else:
print(f"Error: {res}")
# Try another query
retrieval2 = RetrievalRequest(
query="what was the temperature on may 4th?"
)
res, status = eca.retrieval.query(data=retrieval2)
if status == 200:
print(f"\nQuery: {retrieval2.query}")
print(f"Response: {res.response}")