Skip to content

Commit

Permalink
added pgserver
Browse files Browse the repository at this point in the history
  • Loading branch information
norton120 committed Dec 2, 2024
1 parent aa36ee2 commit bf16f6c
Show file tree
Hide file tree
Showing 4 changed files with 1,034 additions and 993 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ __pycache__/
develop-eggs/
downloads/
eggs#letta/letta-server:0.3.7
installable_apps/.eggs
MANIFEST

# PyInstaller
Expand Down
25 changes: 16 additions & 9 deletions letta/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
import pgserver

from letta.local_llm.constants import DEFAULT_WRAPPER_NAME

Expand Down Expand Up @@ -86,19 +87,25 @@ def letta_pg_uri(self) -> str:
elif self.pg_db and self.pg_user and self.pg_password and self.pg_host and self.pg_port:
return f"postgresql+pg8000://{self.pg_user}:{self.pg_password}@{self.pg_host}:{self.pg_port}/{self.pg_db}"
else:
return f"postgresql+pg8000://letta:letta@localhost:5432/letta"
# start the pg binary. This is the default in-memory postgres that replaces SQLite/Chroma
db = self.launch_pg_binary()
return db.uri

# add this property to avoid being returned the default
# reference: https://github.com/cpacker/Letta/issues/1362
@property
def letta_pg_uri_no_default(self) -> str:
if self.pg_uri:
return self.pg_uri
elif self.pg_db and self.pg_user and self.pg_password and self.pg_host and self.pg_port:
return f"postgresql+pg8000://{self.pg_user}:{self.pg_password}@{self.pg_host}:{self.pg_port}/{self.pg_db}"
else:
return None
"""DEPRECATED: now that we have a default in-memory postgres, this is the same as letta_pg_uri"""
return self.letta_pg_uri

def launch_pg_binary(self) -> "str":
pgdata = settings.letta_dir / "pgdata"
pgdata.mkdir(parents=True, exist_ok=True)

database = pgserver.get_server(pgdata)

# create pg vector extension
database.psql('CREATE EXTENSION IF NOT EXISTS vector')

return database.get_uri()

class TestSettings(Settings):
model_config = SettingsConfigDict(env_prefix="letta_test_")
Expand Down
Loading

0 comments on commit bf16f6c

Please sign in to comment.