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

VectorDB support (pgvector) for archival memory #226

Merged
merged 102 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
89cf976
mark depricated API section
sarahwooders Oct 30, 2023
be6212c
add readme
sarahwooders Oct 31, 2023
b011380
add readme
sarahwooders Oct 31, 2023
59f7b71
add readme
sarahwooders Oct 31, 2023
176538b
add readme
sarahwooders Oct 31, 2023
9905266
add readme
sarahwooders Oct 31, 2023
3606959
add readme
sarahwooders Oct 31, 2023
c48803c
add readme
sarahwooders Oct 31, 2023
40cdb23
add readme
sarahwooders Oct 31, 2023
ff43c98
add readme
sarahwooders Oct 31, 2023
01db319
CLI bug fixes for azure
sarahwooders Oct 31, 2023
a11cef9
check azure before running
sarahwooders Oct 31, 2023
a47d49e
Merge branch 'cpacker:main' into main
sarahwooders Oct 31, 2023
fbe2482
Update README.md
sarahwooders Oct 31, 2023
446a1a1
Update README.md
sarahwooders Oct 31, 2023
1541482
bug fix with persona loading
sarahwooders Oct 31, 2023
5776e30
Merge branch 'main' of github.com:sarahwooders/MemGPT
sarahwooders Oct 31, 2023
d48cf23
Merge branch 'cpacker:main' into main
sarahwooders Oct 31, 2023
7a8eb80
remove print
sarahwooders Oct 31, 2023
9a5ece0
Merge branch 'main' of github.com:sarahwooders/MemGPT
sarahwooders Oct 31, 2023
c627089
add initial postgres implementation
sarahwooders Oct 31, 2023
3485b9e
working chroma loading
sarahwooders Nov 1, 2023
54b37be
add postgres tests
sarahwooders Nov 1, 2023
ce6f17e
working initial load into postgres and chroma
sarahwooders Nov 1, 2023
d59ed20
add load index command
sarahwooders Nov 1, 2023
e925a21
semi working load index
sarahwooders Nov 1, 2023
920c27f
disgusting import code thanks to llama index's nasty APIs
sarahwooders Nov 1, 2023
b55cdad
add postgres connector
sarahwooders Nov 2, 2023
3d904f5
working postgres integration
sarahwooders Nov 2, 2023
8a509ad
working local storage (changed saving)
sarahwooders Nov 3, 2023
d3370b3
merge
sarahwooders Nov 3, 2023
d16f12c
merge
sarahwooders Nov 3, 2023
60ecc8a
implement /attach
sarahwooders Nov 3, 2023
2ec39c0
get /attach to work for postgres
sarahwooders Nov 3, 2023
13f4bf9
add tests
sarahwooders Nov 3, 2023
b353440
remove old code
sarahwooders Nov 3, 2023
5ecdbc7
split up storage conenctors into multiple files
sarahwooders Nov 3, 2023
db5952f
update README
sarahwooders Nov 3, 2023
6c82d67
remove unused code
sarahwooders Nov 3, 2023
ea9d1ef
cleanup
sarahwooders Nov 3, 2023
54b1326
add __len__ to EmbeddingArchival
sarahwooders Nov 3, 2023
24601d9
implement vector db loading
sarahwooders Nov 3, 2023
584de80
cleanup state savign
sarahwooders Nov 3, 2023
c19c2ce
Merge branch 'cpacker:main' into main
sarahwooders Nov 3, 2023
d6e2e56
add initial postgres implementation
sarahwooders Oct 31, 2023
ed60397
working chroma loading
sarahwooders Nov 1, 2023
e7cffd3
add postgres tests
sarahwooders Nov 1, 2023
08c5bc0
working initial load into postgres and chroma
sarahwooders Nov 1, 2023
6b461ee
add load index command
sarahwooders Nov 1, 2023
011c2b3
semi working load index
sarahwooders Nov 1, 2023
045f890
disgusting import code thanks to llama index's nasty APIs
sarahwooders Nov 1, 2023
42e754e
add postgres connector
sarahwooders Nov 2, 2023
c24c830
working postgres integration
sarahwooders Nov 2, 2023
991ffd7
working local storage (changed saving)
sarahwooders Nov 3, 2023
f58de60
implement /attach
sarahwooders Nov 3, 2023
efcbac0
get /attach to work for postgres
sarahwooders Nov 3, 2023
eef7e13
add tests
sarahwooders Nov 3, 2023
3a6068b
remove old code
sarahwooders Nov 3, 2023
5df1ff9
split up storage conenctors into multiple files
sarahwooders Nov 3, 2023
0bbf351
update README
sarahwooders Nov 3, 2023
5862918
remove unused code
sarahwooders Nov 3, 2023
e914cbf
cleanup
sarahwooders Nov 3, 2023
2c85c21
add __len__ to EmbeddingArchival
sarahwooders Nov 3, 2023
47d1618
implement vector db loading
sarahwooders Nov 3, 2023
18b5855
cleanup state savign
sarahwooders Nov 3, 2023
4b02244
cleanup
sarahwooders Nov 3, 2023
753e58c
rebase
sarahwooders Nov 3, 2023
f0fc1b8
black formatting
cpacker Nov 3, 2023
7d0bf7c
chroma realtime install
cpacker Nov 3, 2023
d09e0bd
disable test
sarahwooders Nov 3, 2023
9baff0d
merge
sarahwooders Nov 3, 2023
1f64714
fix insert for local
sarahwooders Nov 3, 2023
3fe48c5
fix archival memory print
sarahwooders Nov 3, 2023
1ca2767
test_storage now works
cpacker Nov 3, 2023
124da2a
Update tests.yml
cpacker Nov 3, 2023
1a2d593
Merge branch 'main' into vectordb
sarahwooders Nov 3, 2023
21a0ce1
black
cpacker Nov 3, 2023
be3cb13
patch No such file or directory: '/home/runner/.memgpt/config'
cpacker Nov 3, 2023
b6bfc29
remove load from new CLI
sarahwooders Nov 3, 2023
970378f
Merge branch 'vectordb' of github.com:sarahwooders/MemGPT into vectordb
sarahwooders Nov 3, 2023
8869734
Add basic configure test
vivi Nov 3, 2023
b2c68e8
enable openai on actions
cpacker Nov 3, 2023
5027f71
debugging secrets
cpacker Nov 3, 2023
a6895a4
Add basic save load test
vivi Nov 3, 2023
2d0d9f2
another diff
cpacker Nov 3, 2023
d0e4332
Make test configure work
vivi Nov 3, 2023
cc2b5ec
sanity check
cpacker Nov 3, 2023
b890d1e
Create sarah-test.yml
sarahwooders Nov 3, 2023
a5d3fc1
Update sarah-test.yml
sarahwooders Nov 3, 2023
2a47aff
sanity 2
cpacker Nov 3, 2023
00f5633
Update sarah-test.yml
sarahwooders Nov 3, 2023
ede85b3
add extra poetry config
cpacker Nov 3, 2023
7a1ee5c
update poetry
sarahwooders Nov 3, 2023
0eef405
Merge branch 'vectordb' of github.com:sarahwooders/MemGPT into vectordb
sarahwooders Nov 3, 2023
d6ea79e
move env up
cpacker Nov 3, 2023
581849a
all the places
cpacker Nov 3, 2023
b9f943e
more
cpacker Nov 3, 2023
59c79f7
put env var in front of poetry run
vivi Nov 3, 2023
6d624c7
add back venv
cpacker Nov 3, 2023
ee29a3a
mimic other yml more
cpacker Nov 3, 2023
d10475e
another mimic
cpacker Nov 3, 2023
6f162a6
change versions
cpacker Nov 3, 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
133 changes: 99 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,12 @@
</details>

<details>
<summary><h2>🗃️ Chat with your data - talk to your SQL database or your local files!</strong></h2></summary>
<strong>SQL Database</strong>
<summary><h2>🗃️ Chat with your data - talk to your local files or SQL database!</strong></h2></summary>
<div align="center">
<img src="https://memgpt.ai/assets/img/sql_demo.gif" alt="MemGPT demo video for sql search" width="800">
</div>
<strong>Local files</strong>
<div align="center">
<img src="https://memgpt.ai/assets/img/preload_archival_demo.gif" alt="MemGPT demo video for sql search" width="800">
<img src="https://memgpt.ai/assets/img/doc.gif" alt="MemGPT demo video for sql search" width="800">
</div>
</details>

<details>
<summary><h2>📄 You can also talk to docs - for example ask about <a href="memgpt/personas/examples/docqa">LlamaIndex</a>!</h1></summary>
<div align="center">
<img src="https://memgpt.ai/assets/img/docqa_demo.gif" alt="MemGPT demo video for llamaindex api docs search" width="800">
</div>
<details>
<summary><b>ChatGPT (GPT-4) when asked the same question:</b></summary>
<div align="center">
<img src="https://memgpt.ai/assets/img/llama_index_gpt4.png" alt="GPT-4 when asked about llamaindex api docs" width="800">
</div>
(Question from https://github.com/run-llama/llama_index/issues/7756)
</details>
</details>

## Quick setup

Join <a href="https://discord.gg/9GEQrxmVyE">Discord</a></strong> and message the MemGPT bot (in the `#memgpt` channel). Then run the following commands (messaged to "MemGPT Bot"):
Expand Down Expand Up @@ -77,34 +58,117 @@ Install MemGPT:
pip install pymemgpt
```

To update the package, run
Add your OpenAI API key to your environment:

```sh
pip install pymemgpt -U

export OPENAI_API_KEY=YOUR_API_KEY # on Linux/Mac
set OPENAI_API_KEY=YOUR_API_KEY # on Windows
$Env:OPENAI_API_KEY = "YOUR_API_KEY" # on Windows (PowerShell)
```
Configure default setting for MemGPT by running:
```
memgpt configure
```
Now, you can run MemGPT with:
```sh
memgpt run
```
The `run` command supports the following optional flags (if set, will override config defaults):
* `--agent`: (str) Name of agent to create or to resume chatting with.
* `--human`: (str) Name of the human to run the agent with.
* `--persona`: (str) Name of agent persona to use.
* `--model`: (str) LLM model to run [gpt-4, gpt-3.5].
* `--preset`: (str) MemGPT preset to run agent with.
* `--data_source`: (str) Name of data source (loaded with `memgpt load`) to connect to agent.
* `--first`: (str) Allow user to sent the first message.
* `--debug`: (bool) Show debug logs (default=False)
* `--no_verify`: (bool) Bypass message verification (default=False)
* `--yes`/`-y`: (bool) Skip confirmation prompt and use defaults (default=False)

You can run the following commands in the MemGPT CLI prompt:
* `/exit`: Exit the CLI
* `/save`: Save a checkpoint of the current agent/conversation state
* `/dump`: View the current message log (see the contents of main context)
* `/memory`: Print the current contents of agent memory
* `/pop`: Undo the last message in the conversation
* `/heartbeat`: Send a heartbeat system message to the agent
* `/memorywarning`: Send a memory warning system message to the agent


Once you exit the CLI with `/exit`, you can resume chatting with the same agent by specifying the agent name in `memgpt run --agent <NAME>`.

### Adding Custom Personas/Humans
You can add new human or persona definitions either by providing a file (using the `-f` flag) or text (using the `--text` flag).
```
# add a human
memgpt add human [-f <FILENAME>] [--text <TEXT>]

Add your OpenAI API key to your environment:
# add a persona
memgpt add persona [-f <FILENAME>] [--text <TEXT>]
```

```sh
# on Linux/Mac
export OPENAI_API_KEY=YOUR_API_KEY
You can view available persona and human files with the following command:
```
memgpt list [human/persona]
```

### Data Sources (i.e. chat with your data)
MemGPT supports pre-loading data into archival memory, so your agent can reference loaded data in your conversations with an agent by specifying the data source with the flag `memgpt run --data-source <NAME>`.

#### Loading Data
We currently support loading from a directory and database dumps. We highly encourage contributions for new data sources, which can be added as a new [CLI data load command](https://github.com/cpacker/MemGPT/blob/main/memgpt/cli/cli_load.py).

Loading from a directorsy:
```
# loading a directory
memgpt load directory --name <NAME> \
[--input_dir <DIRECTORY>] [--input-files <FILE1> <FILE2>...] [--recursive]
```
Loading from a database dump:
```sh
# on Windows
set OPENAI_API_KEY=YOUR_API_KEY
memgpt load database --name <NAME> \
--query <QUERY> \ # Query to run on database to get data
--dump-path <PATH> \ # Path to dump file
--scheme <SCHEME> \ # Database scheme
--host <HOST> \ # Database host
--port <PORT> \ # Database port
--user <USER> \ # Database user
--password <PASSWORD> \ # Database password
--dbname <DB_NAME> # Database name
```
To encourage your agent to reference its archival memory, we recommend adding phrases like "search your archival memory..." for the best results.

```sh
# on Windows (PowerShell)
$Env:OPENAI_API_KEY = "YOUR_API_KEY"
#### Viewing available data sources
You can view loaded data source with:
```
memgpt list sources
```

To run MemGPT for as a conversation agent in CLI mode, simply run `memgpt`:
### Using other endpoints

#### Azure
To use MemGPT with Azure, expore the following variables and then re-run `memgpt configure`:
```sh
memgpt
# see https://github.com/openai/openai-python#microsoft-azure-endpoints
export AZURE_OPENAI_KEY = ...
export AZURE_OPENAI_ENDPOINT = ...
export AZURE_OPENAI_VERSION = ...

# set the below if you are using deployment ids
export AZURE_OPENAI_DEPLOYMENT = ...
export AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT = ...
```

#### Custom Endpoints
To use custom endpoints, run `export OPENAI_API_BASE=<MY_CUSTOM_URL>` and then re-run `memgpt configure` to set the custom endpoint as the default endpoint.





<details>
<summary><h2>Deprecated API</h2></summary>
<details>
<summary><strong>Debugging command not found</strong></summary>

Expand Down Expand Up @@ -330,6 +394,7 @@ MemGPT also enables you to chat with docs -- try running this example to talk to
If you downloaded from Hugging Face, it will be `memgpt/personas/docqa/llamaindex-api-docs`.
If you built the index yourself, it will be `memgpt/personas/docqa`.
</details>
</details>

## Support

Expand Down
22 changes: 17 additions & 5 deletions memgpt/cli/cli_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@

from typing import List
import typer
from memgpt.embeddings import Index

app = typer.Typer()


@app.command("index")
def load_index(
name: str = typer.Option(help="Name of dataset to load."), dir: str = typer.Option(help="Path to directory containing index.")
):
"""Load a LlamaIndex saved VectorIndex into MemGPT"""
pass


@app.command("directory")
def load_directory(
name: str = typer.Option(help="Name of dataset to load."),
Expand All @@ -37,11 +46,14 @@ def load_directory(
print("Loading data...")
docs = reader.load_data()

# embed docs
print("Indexing documents...")
index = get_index(name, docs)
# save connector information into .memgpt metadata file
save_index(index, name)
index = Index(name)
index.load_documents(docs)

## embed docs
# print("Indexing documents...")
# index = get_index(name, docs)
## save connector information into .memgpt metadata file
# save_index(index, name)


@app.command("webpage")
Expand Down
43 changes: 38 additions & 5 deletions memgpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MemGPTConfig:

# embedding parameters
embedding_model: str = "openai"
embedding_dim: int = 768
embedding_dim: int = 1536
embedding_chunk_size: int = 300 # number of tokens

# database configs: archival
Expand All @@ -90,8 +90,18 @@ def generate_uuid() -> str:
@classmethod
def load(cls) -> "MemGPTConfig":
config = configparser.ConfigParser()
if os.path.exists(MemGPTConfig.config_path):
config.read(MemGPTConfig.config_path)

# allow overriding with env variables
print("env", os.getenv("MEMGPT_CONFIG_PATH"))
if os.getenv("MEMGPT_CONFIG_PATH"):
config_path = os.getenv("MEMGPT_CONFIG_PATH")
else:
config_path = MemGPTConfig.config_path

print("config path", config_path)

if os.path.exists(config_path):
config.read(config_path)

# read config values
model = config.get("defaults", "model")
Expand Down Expand Up @@ -119,6 +129,11 @@ def load(cls) -> "MemGPTConfig":
embedding_dim = config.getint("embedding", "dim")
embedding_chunk_size = config.getint("embedding", "chunk_size")

# archival storage
archival_storage_type = config.get("archival_storage", "type")
archival_storage_path = config.get("archival_storage", "path") if config.has_option("archival_storage", "path") else None
archival_storage_uri = config.get("archival_storage", "uri") if config.has_option("archival_storage", "uri") else None

anon_clientid = config.get("client", "anon_clientid")

return cls(
Expand All @@ -137,11 +152,15 @@ def load(cls) -> "MemGPTConfig":
embedding_model=embedding_model,
embedding_dim=embedding_dim,
embedding_chunk_size=embedding_chunk_size,
archival_storage_type=archival_storage_type,
archival_storage_path=archival_storage_path,
archival_storage_uri=archival_storage_uri,
anon_clientid=anon_clientid,
config_path=config_path,
)

anon_clientid = MemGPTConfig.generate_uuid()
config = cls(anon_clientid=anon_clientid)
config = cls(anon_clientid=anon_clientid, config_path=config_path)
config.save() # save updated config
return config

Expand Down Expand Up @@ -179,6 +198,15 @@ def save(self):
config.set("embedding", "dim", str(self.embedding_dim))
config.set("embedding", "chunk_size", str(self.embedding_chunk_size))

# archival storage
config.add_section("archival_storage")
print("archival storage", self.archival_storage_type)
config.set("archival_storage", "type", self.archival_storage_type)
if self.archival_storage_path:
config.set("archival_storage", "path", self.archival_storage_path)
if self.archival_storage_uri:
config.set("archival_storage", "uri", self.archival_storage_uri)

# client
config.add_section("client")
if not self.anon_clientid:
Expand All @@ -190,7 +218,12 @@ def save(self):

@staticmethod
def exists():
return os.path.exists(MemGPTConfig.config_path)
# allow overriding with env variables
if os.getenv("MEMGPT_CONFIG_PATH"):
config_path = os.getenv("MEMGPT_CONFIG_PATH")
else:
config_path = MemGPTConfig.config_path
return os.path.exists(config_path)

@staticmethod
def create_config_dir():
Expand Down
Loading
Loading