chroma_client = ChromaClient()RAG Agent
dog_docs = [
{
'id': 'dog1',
'text': 'The Golden Retriever is a friendly, intelligent breed known for its golden coat. They make excellent family pets and are great with children.',
'metadata': {'breed': 'Golden Retriever'}
},
{
'id': 'dog2',
'text': 'German Shepherds are loyal, protective dogs often used in police work. They are highly trainable and good at various tasks.',
'metadata': {'breed': 'German Shepherd'}
},
{
'id': 'dog3',
'text': 'The Golden Retriever is a friendly, intelligent breed with a beautiful golden coat. They are wonderful family pets that get along well with kids.',
'metadata': {'breed': 'Golden Retriever'} # Near duplicate of dog1
},
{
'id': 'dog4',
'text': 'Huskies are energetic working dogs bred for cold climates. They have thick fur and often blue eyes.',
'metadata': {'breed': 'Husky'}
},
{
'id': 'dog5',
'text': 'Siberian Huskies are active working dogs that thrive in cold weather. They are known for their thick coats and striking blue eyes.',
'metadata': {'breed': 'Husky'} # Near duplicate of dog4
}
]
# Add documents to index
chroma_client.add_collection("dog_docs",exists_ok=True)
chroma_client.upsert(collection_name="dog_docs",docs=dog_docs)[{'id': 'dog1',
'text': 'The Golden Retriever is a friendly, intelligent breed known for its golden coat. They make excellent family pets and are great with children.',
'metadata': {'breed': 'Golden Retriever'}},
{'id': 'dog2',
'text': 'German Shepherds are loyal, protective dogs often used in police work. They are highly trainable and good at various tasks.',
'metadata': {'breed': 'German Shepherd'}},
{'id': 'dog3',
'text': 'The Golden Retriever is a friendly, intelligent breed with a beautiful golden coat. They are wonderful family pets that get along well with kids.',
'metadata': {'breed': 'Golden Retriever'}},
{'id': 'dog4',
'text': 'Huskies are energetic working dogs bred for cold climates. They have thick fur and often blue eyes.',
'metadata': {'breed': 'Husky'}},
{'id': 'dog5',
'text': 'Siberian Huskies are active working dogs that thrive in cold weather. They are known for their thick coats and striking blue eyes.',
'metadata': {'breed': 'Husky'}}]
RagFactory
RagFactory (db:stringdale.db.ChromaClient, collection_name:str, k:int, model:str='gpt-4o-mini', system_prompt:str=None)
*A diagram Factory for a RAG workflow.
Args: db: A ChromaClient instance. collection_name: The name of the collection to use. k: The number of documents to retrieve. system_prompt: A system prompt to use for the RAG workflow. make sure to include references to the documents in the system prompt. documents are fed to the prompt under the key ‘docs’ which is a list of dictionaries whose ‘text’ key is the document text.
Returns: A Rag diagram schema.*
D = RagFactory(db=chroma_client,collection_name='dog_docs',k=2)
D.draw()d=D()
for trace in d.run({'query':'tell me some stuff about golden retrievers'}):
trace.pprint()---
name: Start
input:
query: tell me some stuff about golden retrievers
output:
query: tell me some stuff about golden retrievers
---
name: get_docs
input:
query: tell me some stuff about golden retrievers
output:
- id: dog3
text: The Golden Retriever is a friendly, intelligent breed with a beautiful golden
coat. They are wonderful family pets that get along well with kids.
metadata:
breed: Golden Retriever
distance: 0.6992775201797485
- id: dog1
text: The Golden Retriever is a friendly, intelligent breed known for its golden
coat. They make excellent family pets and are great with children.
metadata:
breed: Golden Retriever
distance: 0.7122190594673157
---
name: chat
input:
question: tell me some stuff about golden retrievers
docs:
- id: dog3
text: The Golden Retriever is a friendly, intelligent breed with a beautiful golden
coat. They are wonderful family pets that get along well with kids.
metadata:
breed: Golden Retriever
distance: 0.6992775201797485
- id: dog1
text: The Golden Retriever is a friendly, intelligent breed known for its golden
coat. They make excellent family pets and are great with children.
metadata:
breed: Golden Retriever
distance: 0.7122190594673157
output:
role: assistant
content: |-
Golden Retrievers are a popular dog breed known for their friendly and intelligent nature. Here are some key points about them:\n\n1. **Temperament**: Golden Retrievers are known for their friendly and gentle demeanor. They are highly sociable and get along well with children and other pets, making them excellent family dogs.\n\n2. **Intelligence**: This breed is highly intelligent and eager to please, which makes them easy to train. They excel in obedience training and are often used as service dogs due to their ability to learn commands quickly.\n\n3. **Physical Characteristics**: Golden Retrievers have a distinctive golden coat that is water-repellent, aiding in outdoor activities. Their fur can vary in shade from light to dark golden.\n\n4. **Exercise Needs**: They are active and energetic dogs that require regular exercise. Daily walks, playtime, and mental stimulation are essential to keep them healthy and happy.\n\n5. **Health Considerations**: While generally healthy, Golden Retrievers are prone to certain genetic conditions, such as hip dysplasia and certain types of cancers. Regular veterinary check-ups are important.\n\n6. **Lifespan**: The average lifespan of a Golden Retriever is around 10 to 12 years.\n\n7. **Versatility**: Besides being great family pets, they are also used in various roles, including therapy, assistance, search and rescue, and as detection dogs.\n\nGolden Retrievers are known for their loyalty and make wonderful companions if trained and socialized properly.
meta:
input_tokens: 97
output_tokens: 302
---
name: End
input:
0:
role: assistant
content: |-
Golden Retrievers are a popular dog breed known for their friendly and intelligent nature. Here are some key points about them:\n\n1. **Temperament**: Golden Retrievers are known for their friendly and gentle demeanor. They are highly sociable and get along well with children and other pets, making them excellent family dogs.\n\n2. **Intelligence**: This breed is highly intelligent and eager to please, which makes them easy to train. They excel in obedience training and are often used as service dogs due to their ability to learn commands quickly.\n\n3. **Physical Characteristics**: Golden Retrievers have a distinctive golden coat that is water-repellent, aiding in outdoor activities. Their fur can vary in shade from light to dark golden.\n\n4. **Exercise Needs**: They are active and energetic dogs that require regular exercise. Daily walks, playtime, and mental stimulation are essential to keep them healthy and happy.\n\n5. **Health Considerations**: While generally healthy, Golden Retrievers are prone to certain genetic conditions, such as hip dysplasia and certain types of cancers. Regular veterinary check-ups are important.\n\n6. **Lifespan**: The average lifespan of a Golden Retriever is around 10 to 12 years.\n\n7. **Versatility**: Besides being great family pets, they are also used in various roles, including therapy, assistance, search and rescue, and as detection dogs.\n\nGolden Retrievers are known for their loyalty and make wonderful companions if trained and socialized properly.
meta:
input_tokens: 97
output_tokens: 302
output:
role: assistant
content: |-
Golden Retrievers are a popular dog breed known for their friendly and intelligent nature. Here are some key points about them:\n\n1. **Temperament**: Golden Retrievers are known for their friendly and gentle demeanor. They are highly sociable and get along well with children and other pets, making them excellent family dogs.\n\n2. **Intelligence**: This breed is highly intelligent and eager to please, which makes them easy to train. They excel in obedience training and are often used as service dogs due to their ability to learn commands quickly.\n\n3. **Physical Characteristics**: Golden Retrievers have a distinctive golden coat that is water-repellent, aiding in outdoor activities. Their fur can vary in shade from light to dark golden.\n\n4. **Exercise Needs**: They are active and energetic dogs that require regular exercise. Daily walks, playtime, and mental stimulation are essential to keep them healthy and happy.\n\n5. **Health Considerations**: While generally healthy, Golden Retrievers are prone to certain genetic conditions, such as hip dysplasia and certain types of cancers. Regular veterinary check-ups are important.\n\n6. **Lifespan**: The average lifespan of a Golden Retriever is around 10 to 12 years.\n\n7. **Versatility**: Besides being great family pets, they are also used in various roles, including therapy, assistance, search and rescue, and as detection dogs.\n\nGolden Retrievers are known for their loyalty and make wonderful companions if trained and socialized properly.
meta:
input_tokens: 97
output_tokens: 302
d.output{'role': 'assistant',
'content': 'Golden Retrievers are a popular dog breed known for their friendly and intelligent nature. Here are some key points about them:\n\n1. **Temperament**: Golden Retrievers are known for their friendly and gentle demeanor. They are highly sociable and get along well with children and other pets, making them excellent family dogs.\n\n2. **Intelligence**: This breed is highly intelligent and eager to please, which makes them easy to train. They excel in obedience training and are often used as service dogs due to their ability to learn commands quickly.\n\n3. **Physical Characteristics**: Golden Retrievers have a distinctive golden coat that is water-repellent, aiding in outdoor activities. Their fur can vary in shade from light to dark golden.\n\n4. **Exercise Needs**: They are active and energetic dogs that require regular exercise. Daily walks, playtime, and mental stimulation are essential to keep them healthy and happy.\n\n5. **Health Considerations**: While generally healthy, Golden Retrievers are prone to certain genetic conditions, such as hip dysplasia and certain types of cancers. Regular veterinary check-ups are important.\n\n6. **Lifespan**: The average lifespan of a Golden Retriever is around 10 to 12 years.\n\n7. **Versatility**: Besides being great family pets, they are also used in various roles, including therapy, assistance, search and rescue, and as detection dogs.\n\nGolden Retrievers are known for their loyalty and make wonderful companions if trained and socialized properly.',
'meta': {'input_tokens': 97, 'output_tokens': 302}}