-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AutonomousResearchGroup/postgres
init postgres, half of tests are passing
- Loading branch information
Showing
15 changed files
with
507 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,39 @@ | ||
import chromadb | ||
|
||
from agentmemory.helpers import debug_log | ||
|
||
storage_path = "./memory" | ||
client = chromadb.PersistentClient(storage_path) | ||
|
||
|
||
def check_client_initialized(): | ||
""" | ||
Check if the client has been initialized, and initialize it if not. | ||
import os | ||
import json | ||
|
||
Example: | ||
>>> check_client_initialized() | ||
""" | ||
if get_chroma_client() is None: | ||
set_chroma_client(chromadb.PersistentClient(storage_path)) | ||
|
||
|
||
def get_chroma_client(): | ||
""" | ||
Get the chromadb client. | ||
import chromadb | ||
import psycopg2 | ||
from sentence_transformers import SentenceTransformer | ||
from dotenv import load_dotenv | ||
|
||
Returns: | ||
chromadb.Client: Chromadb client. | ||
from agentmemory.postgres import PostgresClient | ||
|
||
Example: | ||
>>> get_chroma_client() | ||
<chromadb.client.Client object at 0x7f7b9c2f0d00> | ||
""" | ||
global client | ||
global storage_path | ||
if client is None: | ||
client = chromadb.PersistentClient(path=storage_path) | ||
return client | ||
load_dotenv() | ||
|
||
|
||
def set_chroma_client(data_storage_path=storage_path): | ||
""" | ||
Set the chromadb client. | ||
DEFAULT_CLIENT_TYPE = "CHROMA" | ||
CLIENT_TYPE = os.environ.get("CLIENT_TYPE", DEFAULT_CLIENT_TYPE) | ||
STORAGE_PATH = os.environ.get("STORAGE_PATH", "./memory") | ||
POSTGRES_CONNECTION_STRING = os.environ.get("POSTGRES_CONNECTION_STRING") | ||
|
||
Args: | ||
storage_path (string): The path to the new directory. | ||
client = None | ||
|
||
Returns: | ||
None | ||
|
||
Example: | ||
>>> set_chroma_client(new_client) | ||
""" | ||
def get_client(client_type=None, *args, **kwargs): | ||
global client | ||
global storage_path | ||
storage_path = data_storage_path | ||
client = chromadb.PersistentClient(storage_path) | ||
debug_log("Set chroma client", {"storage_path": storage_path}, "system") | ||
if client is not None: | ||
return client | ||
|
||
if client_type is None: | ||
client_type = CLIENT_TYPE | ||
|
||
if client_type == "POSTGRES": | ||
if POSTGRES_CONNECTION_STRING is None: | ||
raise EnvironmentError( | ||
"Postgres connection string not set in environment variables!" | ||
) | ||
client = PostgresClient(POSTGRES_CONNECTION_STRING) | ||
else: | ||
client = chromadb.PersistentClient(path=STORAGE_PATH, *args, **kwargs) | ||
|
||
return client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.