-
Notifications
You must be signed in to change notification settings - Fork 44.4k
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
Pinecone Vectorized Memory #122
Merged
Torantulino
merged 2 commits into
Significant-Gravitas:master
from
dschonholtz:pinecone-memory
Apr 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -139,6 +139,35 @@ export CUSTOM_SEARCH_ENGINE_ID="YOUR_CUSTOM_SEARCH_ENGINE_ID" | |||||
|
||||||
``` | ||||||
|
||||||
## 🌲 Pinecone API Key Setup | ||||||
|
||||||
Pinecone enable a vector based memory so a vast memory can be stored and only relevant memories | ||||||
are loaded for the agent at any given time. | ||||||
|
||||||
1. Go to app.pinecone.io and make an account if you don't already have one. | ||||||
2. Choose the `Starter` plan to avoid being charged. | ||||||
3. Find your API key and region under the default project in the left sidebar. | ||||||
|
||||||
### Setting up environment variables | ||||||
For Windows Users: | ||||||
``` | ||||||
setx PINECONE_API_KEY "YOUR_GOOGLE_API_KEY" | ||||||
export PINECONE_ENV="Your region" # something like: us-east4-gcp | ||||||
|
||||||
``` | ||||||
For macOS and Linux users: | ||||||
``` | ||||||
export PINECONE_API_KEY="YOUR_GOOGLE_API_KEY" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
export PINECONE_ENV="Your region" # something like: us-east4-gcp | ||||||
|
||||||
``` | ||||||
|
||||||
Or you can set them in the `.env` file. | ||||||
|
||||||
## View Memory Usage | ||||||
|
||||||
1. View memory usage by using the `--debug` flag :) | ||||||
|
||||||
## 💀 Continuous Mode ⚠️ | ||||||
Run the AI **without** user authorisation, 100% automated. | ||||||
Continuous mode is not recommended. | ||||||
|
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
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,29 +1,27 @@ | ||
CONSTRAINTS: | ||
|
||
1. ~4000 word limit for memory. Your memory is short, so immediately save important information to long term memory and code to files. | ||
2. No user assistance | ||
3. Exclusively use the commands listed in double quotes e.g. "command name" | ||
1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files. | ||
2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
3. No user assistance | ||
4. Exclusively use the commands listed in double quotes e.g. "command name" | ||
|
||
COMMANDS: | ||
|
||
1. Google Search: "google", args: "input": "<search>" | ||
2. Memory Add: "memory_add", args: "string": "<string>" | ||
3. Memory Delete: "memory_del", args: "key": "<key>" | ||
4. Memory Overwrite: "memory_ovr", args: "key": "<key>", "string": "<string>" | ||
5. Browse Website: "browse_website", args: "url": "<url>", "question": "<what_you_want_to_find_on_website>" | ||
6. Start GPT Agent: "start_agent", args: "name": <name>, "task": "<short_task_desc>", "prompt": "<prompt>" | ||
7. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>" | ||
8. List GPT Agents: "list_agents", args: "" | ||
9. Delete GPT Agent: "delete_agent", args: "key": "<key>" | ||
10. Write to file: "write_to_file", args: "file": "<file>", "text": "<text>" | ||
11. Read file: "read_file", args: "file": "<file>" | ||
12. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>" | ||
13. Delete file: "delete_file", args: "file": "<file>" | ||
14. Evaluate Code: "evaluate_code", args: "code": "<full _code_string>" | ||
15. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>" | ||
16. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>" | ||
17. Execute Python File: "execute_python_file", args: "file": "<file>" | ||
18. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>" | ||
2. Browse Website: "browse_website", args: "url": "<url>", "question": "<what_you_want_to_find_on_website>" | ||
3. Start GPT Agent: "start_agent", args: "name": <name>, "task": "<short_task_desc>", "prompt": "<prompt>" | ||
4. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>" | ||
5. List GPT Agents: "list_agents", args: "" | ||
6. Delete GPT Agent: "delete_agent", args: "key": "<key>" | ||
7. Write to file: "write_to_file", args: "file": "<file>", "text": "<text>" | ||
8. Read file: "read_file", args: "file": "<file>" | ||
9. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>" | ||
10. Delete file: "delete_file", args: "file": "<file>" | ||
11. Evaluate Code: "evaluate_code", args: "code": "<full _code_string>" | ||
12. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>" | ||
13. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>" | ||
14. Execute Python File: "execute_python_file", args: "file": "<file>" | ||
15. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>" | ||
|
||
RESOURCES: | ||
|
||
|
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 +1,61 @@ | ||
permanent_memory = [] | ||
from config import Config, Singleton | ||
import pinecone | ||
import openai | ||
|
||
cfg = Config() | ||
|
||
|
||
def get_ada_embedding(text): | ||
text = text.replace("\n", " ") | ||
return openai.Embedding.create(input=[text], model="text-embedding-ada-002")["data"][0]["embedding"] | ||
|
||
|
||
def get_text_from_embedding(embedding): | ||
return openai.Embedding.retrieve(embedding, model="text-embedding-ada-002")["data"][0]["text"] | ||
|
||
|
||
class PineconeMemory(metaclass=Singleton): | ||
def __init__(self): | ||
pinecone_api_key = cfg.pinecone_api_key | ||
pinecone_region = cfg.pinecone_region | ||
pinecone.init(api_key=pinecone_api_key, environment=pinecone_region) | ||
dimension = 1536 | ||
metric = "cosine" | ||
pod_type = "p1" | ||
table_name = "auto-gpt" | ||
# this assumes we don't start with memory. | ||
# for now this works. | ||
# we'll need a more complicated and robust system if we want to start with memory. | ||
self.vec_num = 0 | ||
if table_name not in pinecone.list_indexes(): | ||
pinecone.create_index(table_name, dimension=dimension, metric=metric, pod_type=pod_type) | ||
self.index = pinecone.Index(table_name) | ||
|
||
def add(self, data): | ||
vector = get_ada_embedding(data) | ||
# no metadata here. We may wish to change that long term. | ||
resp = self.index.upsert([(str(self.vec_num), vector, {"raw_text": data})]) | ||
_text = f"Inserting data into memory at index: {self.vec_num}:\n data: {data}" | ||
self.vec_num += 1 | ||
return _text | ||
|
||
def get(self, data): | ||
return self.get_relevant(data, 1) | ||
|
||
def clear(self): | ||
self.index.delete(deleteAll=True) | ||
return "Obliviated" | ||
|
||
def get_relevant(self, data, num_relevant=5): | ||
""" | ||
Returns all the data in the memory that is relevant to the given data. | ||
:param data: The data to compare to. | ||
:param num_relevant: The number of relevant data to return. Defaults to 5 | ||
""" | ||
query_embedding = get_ada_embedding(data) | ||
results = self.index.query(query_embedding, top_k=num_relevant, include_metadata=True) | ||
sorted_results = sorted(results.matches, key=lambda x: x.score) | ||
return [str(item['metadata']["raw_text"]) for item in sorted_results] | ||
|
||
def get_stats(self): | ||
return self.index.describe_index_stats() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.