Skip to content

Commit

Permalink
Feat/refactor vector database (#41)
Browse files Browse the repository at this point in the history
* Refactor vector database implementation

* Small tweaks
  • Loading branch information
homanp authored Feb 15, 2024
1 parent 064dc32 commit 18adba6
Show file tree
Hide file tree
Showing 10 changed files with 518 additions and 479 deletions.
5 changes: 3 additions & 2 deletions api/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

from models.delete import RequestPayload, ResponsePayload
from service.embedding import get_encoder
from service.vector_database import VectorService, get_vector_service
from vectordbs import get_vector_service
from vectordbs.base import BaseVectorDatabase

router = APIRouter()


@router.delete("/delete", response_model=ResponsePayload)
async def delete(payload: RequestPayload):
encoder = get_encoder(encoder_type=payload.encoder)
vector_service: VectorService = get_vector_service(
vector_service: BaseVectorDatabase = get_vector_service(
index_name=payload.index_name,
credentials=payload.vector_database,
encoder=encoder,
Expand Down
2 changes: 1 addition & 1 deletion service/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from models.document import BaseDocument, BaseDocumentChunk
from models.file import File
from models.ingest import EncoderEnum
from service.vector_database import get_vector_service
from utils.logger import logger
from utils.summarise import completion
from vectordbs import get_vector_service


class EmbeddingService:
Expand Down
8 changes: 4 additions & 4 deletions service/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from models.document import BaseDocumentChunk
from models.query import RequestPayload
from service.embedding import get_encoder
from service.vector_database import VectorService, get_vector_service
from utils.logger import logger
from utils.summarise import SUMMARY_SUFFIX
from vectordbs import BaseVectorDatabase, get_vector_service


def create_route_layer() -> RouteLayer:
Expand All @@ -29,7 +29,7 @@ def create_route_layer() -> RouteLayer:


async def get_documents(
*, vector_service: VectorService, payload: RequestPayload
*, vector_service: BaseVectorDatabase, payload: RequestPayload
) -> list[BaseDocumentChunk]:
chunks = await vector_service.query(input=payload.input, top_k=25)

Expand All @@ -47,14 +47,14 @@ async def query(payload: RequestPayload) -> list[BaseDocumentChunk]:
encoder = get_encoder(encoder_type=payload.encoder)

if decision == "summarize":
vector_service: VectorService = get_vector_service(
vector_service: BaseVectorDatabase = get_vector_service(
index_name=f"{payload.index_name}{SUMMARY_SUFFIX}",
credentials=payload.vector_database,
encoder=encoder,
)
return await get_documents(vector_service=vector_service, payload=payload)

vector_service: VectorService = get_vector_service(
vector_service: BaseVectorDatabase = get_vector_service(
index_name=payload.index_name,
credentials=payload.vector_database,
encoder=encoder,
Expand Down
Loading

0 comments on commit 18adba6

Please sign in to comment.