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

feat: Embedded Postgresql #2134

Merged
merged 4 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
1 change: 1 addition & 0 deletions letta/server/rest_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def on_startup():
# Tool.load_default_tools(get_db_session())

generate_openapi_schema(app)
# always migrate now that we have a default in-memory postgres

@app.on_event("shutdown")
def on_shutdown():
Expand Down
26 changes: 17 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,18 +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
self.pg_uri = self.launch_pg_binary()
return self.pg_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):
Expand Down
Loading
Loading