> For the complete documentation index, see [llms.txt](https://openagi.aiplanet.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openagi.aiplanet.com/components/vectorstore/chromastorage.md).

# 💾 ChromaStorage

The `ChromaStorage` class is a specific implementation of the `Storage` class using `ChromaDB`. Here is how you can use it:

```python
class ChromaMemory(BaseModel):
    storage: BaseStorage = Field(
        default=ChromaStorage,
        description="Storage to be used for the Memory.",
        exclude=True,
    )

    def model_post_init(self, __context: Any) -> None:
        instance = super().model_post_init(__context)
        self.storage = ChromaStorage.from_kwargs(collection_name=self.sessiond_id)
        return instance
```

```python
class ChromaMemory(BaseModel):
    sessiond_id: str = Field(default=uuid4().hex)
    storage: BaseStorage = Field(
        default=ChromaStorage,
        description="Storage to be used for the Memory.",
        exclude=True,
    )

    def model_post_init(self, __context: Any) -> None:
        inst = super().model_post_init(__context)
        logging.info(f"{self.sessiond_id=}")
        self.storage = ChromaStorage.from_kwargs(collection_name=self.sessiond_id)
        return inst

    def search(self, query: str, n_results: int = 10, **kwargs) -> Dict[str, Any]:
        """Search for similar tasks based on a query."""
        query_data = {
            "query_texts": query,
            "n_results": n_results,
            "where": {"$contains": self.sessiond_id},
            **kwargs,
        }
        return self.storage.query_documents(**query_data)

    def display_memory(self) -> Dict[str, Any]:
        """Retrieve and display the current memory state from the database."""
        result = self.storage.query_documents(self.session_id, n_results=2)
        if result:
            return result
        return {}

    def save_task(self, task: Task) -> None:
        """Save execution details into Memory."""
        document = task.result
        metadata = {
            "task_id": task.id,
            "session_id": self.sessiond_id,
            "task_name": task.name,
            "task_description": task.description,
            "task_result": task.result,
            "task_actions": task.actions,
        }

        return self.storage.save_document(
            id=task.id,
            document=document,
            metadata=metadata,
        )

    def save_planned_tasks(self, tasks: TaskLists):
        for task in tasks:
            self.save_task(task=task)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://openagi.aiplanet.com/components/vectorstore/chromastorage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
