import cycls
# Initialize the agent with dependencies
agent = cycls.Agent(pip=["chromadb", "openai"])
@agent("chroma-agent", title="RAG Agent")
async def search_agent(context):
import chromadb
from chromadb.utils import embedding_functions
# Setup OpenAI Embedding Function
openai_ef = embedding_functions.OpenAIEmbeddingFunction(
api_key="YOUR_OPENAI_KEY", # Replace with your actual key
model_name="text-embedding-3-small"
)
# Initialize ChromaDB client
client = chromadb.Client()
# Create collection with the embedding function
collection = client.get_or_create_collection(
name="docs",
embedding_function=openai_ef
)
# Add documents to the collection
collection.add(
documents=["I love cats", "I love dogs", "The weather is nice"],
ids=["1", "2", "3"]
)
# Query using the latest message
query = context.messages[-1]["content"]
results = collection.query(query_texts=[query], n_results=1)
# Return retrieved context
retrieved_doc = results['documents'][0][0]
yield f"Context: {retrieved_doc}"
# Run locally
agent.deploy(prod=False)