Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chroma memory #852

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c0a240f
first chroma commit
jhouseke Apr 6, 2023
5028f0f
added serendipity algorithm, continued efforts
jhouseke Apr 6, 2023
c8dc4e3
first chroma commit
jhouseke Apr 6, 2023
e4f87d4
added serendipity algorithm, continued efforts
jhouseke Apr 6, 2023
556fdb5
Merge branch 'chroma-memory' of https://github.com/jhouseke/Auto-GPT …
jhouseke Apr 11, 2023
ac22636
refactor of chroma memory implementation
jhouseke Apr 11, 2023
331b333
removed serendipity algorithm
jhouseke Apr 11, 2023
d39025c
fixed .env.template
jhouseke Apr 11, 2023
c9439c3
removed call to memory function in chat.py
jhouseke Apr 11, 2023
662b125
bug fixes
jhouseke Apr 11, 2023
9d0f7c0
bug fix
jhouseke Apr 11, 2023
84d0005
bug fixes
jhouseke Apr 11, 2023
85bd5b4
bug fixes
jhouseke Apr 11, 2023
585c01c
added final newlines
jhouseke Apr 12, 2023
b914363
changed environment variables to underscore
jhouseke Apr 12, 2023
073740a
Merge branch 'master' into chroma-memory
jhouseke Apr 12, 2023
9fa7694
Merge branch 'master' into chroma-memory
jhouseke Apr 15, 2023
7640367
refactor to comply with new commits
jhouseke Apr 15, 2023
68fc363
Merge branch 'master' into chroma-memory
jhouseke Apr 17, 2023
6f942b9
fixed W293, removed whitespace
jhouseke Apr 17, 2023
35a092f
resolved additional linting issues
jhouseke Apr 17, 2023
1dbdd4e
Merge branch 'master' into chroma-memory
jhouseke Apr 17, 2023
8666284
Merge branch 'master' into chroma-memory
jhouseke Apr 27, 2023
591472f
chroma import fixes
jhouseke Apr 27, 2023
54a6ab7
Merge branch 'chroma-memory' of https://github.com/jhouseke/Auto-GPT …
jhouseke Apr 27, 2023
30ac50e
Merge branch 'master' into chroma-memory
jhouseke May 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ OPENAI_API_KEY=your-openai-api-key
# MILVUS_SECURE=
# MILVUS_COLLECTION=autogpt

### CHROMADB
# CHROMA_DB_DIRECTORY - ChromaDB directory if using local instance
# CHROMA_SERVER_HOST - ChromaDB server host if using remote instance
# CHROMA_SERVER_PORT - ChromaDB server port if using remote instance
CHROMA_SERVER_HOST=
CHROMA_SERVER_PORT=
CHROMA_DB_DIRECTORY=your-chroma-db-directory

################################################################################
### IMAGE GENERATION PROVIDER
################################################################################
Expand Down
8 changes: 7 additions & 1 deletion autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def __init__(self) -> None:
self.pinecone_api_key = os.getenv("PINECONE_API_KEY")
self.pinecone_region = os.getenv("PINECONE_ENV")

self.weaviate_host = os.getenv("WEAVIATE_HOST")
#chroma configuration
self.chroma_db_directory = os.getenv("CHROMA_DB_DIRECTORY")
self.chroma_server_host = os.getenv("CHROMA_SERVER_HOST")
self.chroma_server_port = os.getenv("CHROMA_SERVER_PORT")

#weaviate configuration
self.weaviate_host = os.getenv("WEAVIATE_HOST")
self.weaviate_port = os.getenv("WEAVIATE_PORT")
self.weaviate_protocol = os.getenv("WEAVIATE_PROTOCOL", "http")
self.weaviate_username = os.getenv("WEAVIATE_USERNAME", None)
Expand Down
19 changes: 19 additions & 0 deletions autogpt/memory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from autogpt.logs import logger
from autogpt.memory.local import LocalCache
from autogpt.memory.no_memory import NoMemory
from autogpt.memory.chroma import ChromaMemory

# List of supported memory backends
# Add a backend to this list if the import attempt is successful
Expand Down Expand Up @@ -34,6 +35,14 @@
except ImportError:
MilvusMemory = None

try:
from autogpt.memory.chroma import ChromaMemory

supported_memory.append("chroma")
except ImportError:
print("Chroma not installed. Skipping import.")
ChromaMemory = None


def get_memory(cfg, init=False):
memory = None
Expand Down Expand Up @@ -71,6 +80,16 @@ def get_memory(cfg, init=False):
)
else:
memory = MilvusMemory(cfg)
elif cfg.memory_backend == "chroma":
if not ChromaMemory:
print(
"Error: Chroma is not installed. Please install chroma-sdk to"
" use Chroma as a memory backend."
)
else:
memory = ChromaMemory(cfg)
if init:
memory.clear()
elif cfg.memory_backend == "no_memory":
memory = NoMemory(cfg)

Expand Down
49 changes: 49 additions & 0 deletions autogpt/memory/chroma.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import chromadb
from chromadb.config import Settings
from chromadb.utils import embedding_functions
import uuid
import os
from datetime import datetime
import random
from memory.base import MemoryProviderSingleton


class ChromaMemory(MemoryProviderSingleton):
def __init__(self, cfg):
if cfg.chroma_db_directory is not None:
self.db = chromadb.Client(Settings(chroma_db_impl="duckdb+parquet", persist_directory=cfg.chroma_db_directory))
elif cfg.chroma_server_host is not None:
self.db = chromadb.Client(Settings(chroma_db_impl="rest", chroma_server_host=cfg.chroma_server_host, chroma_server_http_port=cfg.chroma_server_port))
else:
self.db = chromadb.Client(Settings(chroma_db_impl="duckdb+parquet", persist_directory="./chromadb"))
self.embedding_function = embedding_functions.SentenceTransformerEmbeddingFunction("paraphrase-MiniLM-L6-v2")
self.collection = self.db.get_or_create_collection(name="autogpt", embedding_function=self.embedding_function)

def add(self, data):
_timestamp = (datetime.now() - datetime(1970, 1, 1)).total_seconds()
if self.collection.add(documents=[data], metadatas=[{"timestamp": _timestamp}], id=[str(uuid.uuid4())]):
return True
return False

def remove(self, data):
_deleted_id = self.collection.remove(data=[str(uuid.uuid4())])
_result = f"Deleted {_deleted_id}"
return _result

def get(self, data):
return self.collection.query(query_texts=[data], n_results=1)

def get_relevant(self, data, num_relevant=5):
try:
results = self.collection.query(query_texts=[data], n_results=num_relevant)
except Exception as e:
print(f"Error querying ChromaDB: {e}")
return None
return results

def clear(self):
self.db.reset()
return "Cleared"

def get_stats(self):
return self.collection.count()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ distro==1.8.0
openai==0.27.2
playsound==1.2.2
python-dotenv==1.0.0
chromadb==0.3.21
pyyaml==6.0
readability-lxml==0.8.1
requests
Expand Down