Skip to content

Commit

Permalink
fix: sql doc store
Browse files Browse the repository at this point in the history
fixes an issue where sql doc store points at the db uri instead of the vector store uri
  • Loading branch information
Erez Sharim authored and asaf committed Jul 4, 2024
1 parent 282b43d commit 7372151
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/ext_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlalchemy import text

from app.models import Document
from app.tx import TransactionContext
from app.sql import SQLAlchemyTransactionContext

collection_table_name = "langchain_pg_collection"
embedding_table_name = "langchain_pg_embedding"
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_document(
id: Optional[str] = "",
external_id: Optional[str] = "",
projection: Optional[List[str]] = [],
tx_context: TransactionContext = None,
tx_context: SQLAlchemyTransactionContext = None,
):
if id == "" and external_id == "":
return None
Expand Down Expand Up @@ -102,7 +102,7 @@ def list_documents(
offset=0,
limit=10,
projection: Optional[List[str]] = [],
tx_context: TransactionContext = None,
tx_context: SQLAlchemyTransactionContext = None,
) -> tuple[List[Document], int]:
stmt = text(
f"SELECT * FROM {collection_table_name} WHERE name = :workspace_id limit 1;"
Expand Down
6 changes: 3 additions & 3 deletions app/routers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from app.data_fetching.utils import Doc, prepare_metadata_ids_content
from app.models import Document, PaginatedListBase, Workspace
from app.services import pagination_params
from app.sql import SQLAlchemyTransactionContext
from app.sql import SQLAlchemyTransactionContext, doc_store_engine

from ..auth import get_current_workspace, setup_workspace_vstore
from ..settings import settings
Expand Down Expand Up @@ -111,7 +111,7 @@ async def get(
ovstore=Depends(setup_workspace_vstore),
_=Depends(is_admin_or_has_scopes(scopes=[Permissions.READ_CONTENT.value])),
):
with SQLAlchemyTransactionContext().manage() as tx_context:
with SQLAlchemyTransactionContext(engine=doc_store_engine).manage() as tx_context:
try:
doc = ovstore.__get_doc__(
workspace_id=workspace.id,
Expand Down Expand Up @@ -142,7 +142,7 @@ async def list(
):
limit = list_params.get("limit", 10)
offset = list_params.get("offset", 0)
with SQLAlchemyTransactionContext().manage() as tx_context:
with SQLAlchemyTransactionContext(engine=doc_store_engine).manage() as tx_context:
try:
docs, total = ovstore.__list_docs__(
workspace_id=workspace.id,
Expand Down
6 changes: 6 additions & 0 deletions app/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
# connect_args={"connect_timeout": 10},
)

doc_store_engine = create_engine(
settings.VSTORE_URI,
echo=True,
# connect_args={"connect_timeout": 10}
)


def create_tables():
from .models_stores_sql import (
Expand Down

0 comments on commit 7372151

Please sign in to comment.