Skip to content

Commit

Permalink
fix redis config
Browse files Browse the repository at this point in the history
  • Loading branch information
azliu0 committed Apr 15, 2024
1 parent 6aebc11 commit e3d6b82
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
5173,
2010,
6379,
6380,
5432
],
"postCreateCommand": "bash scripts/devcontainer_setup.sh",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
image: redis/redis-stack-server:7.2.0-v6
restart: unless-stopped
ports:
- "6380:6379"
- "6379:6379"
volumes:
- data:/home/pigeon
networks:
Expand Down
17 changes: 17 additions & 0 deletions server/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def _generate_test_documents():
return test_documents


def _embed_existing_documents(documents: list[Document]):
"""Embed existing documents."""
to_embed_documents = [
{
"question": doc.question,
"source": doc.source,
"content": doc.content,
"sql_id": doc.id,
}
for doc in documents
]
embed_corpus(to_embed_documents)


@seed.cli.command()
def corpus():
"""Add test documents to the corpus."""
Expand All @@ -70,6 +84,9 @@ def email():
print("No documents in the database. Generating test documents...")
test_documents = _generate_test_documents()
embed_corpus(test_documents)
else:
print("Embedding existing documents...")
_embed_existing_documents(docs)

subject = "Test Email Subject"
body = "Hello! What is blueprint?"
Expand Down
3 changes: 1 addition & 2 deletions server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def _get_config_option(name: str, default_value: str | None = None) -> str:
SQLALCHEMY_DATABASE_URI = _get_config_option(
"DATABASE_URL", "postgresql://postgres:password@database/pigeondb"
)
REDIS_URL = _get_config_option("REDIS_URL", "redis")
REDIS_DB_INDEX = _get_config_option("REDIS_DB_INDEX", "0")
REDIS_HOST = _get_config_option("REDIS_HOST", "redis")

FLASK_RUN_PORT = 2010
DEBUG = True
Expand Down
6 changes: 2 additions & 4 deletions server/nlp/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@
from redis.commands.search.indexDefinition import IndexDefinition, IndexType
from redis.commands.search.query import Query

from server.config import REDIS_DB_INDEX, REDIS_URL, RedisDocument
from server.config import REDIS_HOST, RedisDocument

cwd = os.path.dirname(__file__)

VECTOR_DIMENSION = 1536

# load redis client
client = redis.Redis(
host=REDIS_URL, port=6379, decode_responses=True, db=int(REDIS_DB_INDEX)
)
client = redis.Redis(host=REDIS_HOST, port=6379, decode_responses=True)

# load corpus
# with open('corpus.json', 'r') as f:
Expand Down
11 changes: 5 additions & 6 deletions server_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,21 @@ def db_url(db_name="pigeondb_test"):

@pytest.fixture(scope="session")
def redis_db_index():
"""Yields test db index for Redis.
"""Yields test redis db host.
Flushes test db if it already exists.
"""
test_db_index = 1
client = redis.Redis(host="redis", port=6379, db=test_db_index)
client = redis.Redis(host="redis-test", port=6379)
client.flushdb()
client.close()

yield test_db_index
yield "redis-test"


@pytest.fixture(scope="session")
def app(db_url: str, redis_db_index: int):
def app(db_url: str, redis_db_index: str):
os.environ["DATABASE_URL"] = db_url
os.environ["REDIS_DB_INDEX"] = str(redis_db_index)
os.environ["REDIS_HOST"] = redis_db_index

app = create_app()
app.config.update(
Expand Down

0 comments on commit e3d6b82

Please sign in to comment.