Mbonea commited on
Commit
eb21184
1 Parent(s): 3bb3721

cache me outside

Browse files
App/Embedding/EmbeddingRoutes.py CHANGED
@@ -2,17 +2,20 @@ from fastapi import APIRouter, BackgroundTasks
2
 
3
  from .utils.Initialize import TextSearch, IdSearch
4
  from .Schemas import SearchRequest, AddDocumentRequest
 
5
 
6
  embeddigs_router = APIRouter(tags=["embeddings"])
7
 
8
 
9
  # create
10
  @embeddigs_router.post("/add_document")
 
11
  async def create_embeddings(req: AddDocumentRequest):
12
  pass
13
 
14
 
15
  @embeddigs_router.post("/search_id")
 
16
  async def search_id(
17
  req: SearchRequest,
18
  background_tasks: BackgroundTasks,
@@ -21,5 +24,6 @@ async def search_id(
21
 
22
 
23
  @embeddigs_router.post("/search_text")
 
24
  async def search_text(req: SearchRequest):
25
  return TextSearch(query=req.query)
 
2
 
3
  from .utils.Initialize import TextSearch, IdSearch
4
  from .Schemas import SearchRequest, AddDocumentRequest
5
+ from fastapi_cache.decorator import cache
6
 
7
  embeddigs_router = APIRouter(tags=["embeddings"])
8
 
9
 
10
  # create
11
  @embeddigs_router.post("/add_document")
12
+ @cache(namespace="cache1")
13
  async def create_embeddings(req: AddDocumentRequest):
14
  pass
15
 
16
 
17
  @embeddigs_router.post("/search_id")
18
+ @cache(namespace="cache2")
19
  async def search_id(
20
  req: SearchRequest,
21
  background_tasks: BackgroundTasks,
 
24
 
25
 
26
  @embeddigs_router.post("/search_text")
27
+ @cache(namespace="cache3")
28
  async def search_text(req: SearchRequest):
29
  return TextSearch(query=req.query)
App/app.py CHANGED
@@ -8,6 +8,8 @@ from .Embedding.EmbeddingRoutes import embeddigs_router
8
 
9
  from fastapi.middleware.cors import CORSMiddleware
10
 
 
 
11
 
12
  import logging
13
 
@@ -33,6 +35,11 @@ app.add_middleware(
33
  app.add_middleware(GZipMiddleware, minimum_size=1000)
34
 
35
 
 
 
 
 
 
36
  @app.get("/")
37
  async def landing_page():
38
  return {"code": 200, "message": "we are back!"}
 
8
 
9
  from fastapi.middleware.cors import CORSMiddleware
10
 
11
+ from fastapi_cache import FastAPICache
12
+ from fastapi_cache.backends.inmemory import InMemoryBackend
13
 
14
  import logging
15
 
 
35
  app.add_middleware(GZipMiddleware, minimum_size=1000)
36
 
37
 
38
+ @app.on_event("startup")
39
+ async def startup():
40
+ FastAPICache.init(InMemoryBackend())
41
+
42
+
43
  @app.get("/")
44
  async def landing_page():
45
  return {"code": 200, "message": "we are back!"}
requirements.txt CHANGED
@@ -6,4 +6,5 @@ langchain
6
  uvicorn[standard]
7
  pydantic
8
  requests
 
9
 
 
6
  uvicorn[standard]
7
  pydantic
8
  requests
9
+ fastapi-cache2[memcache]
10