Skip to content

Commit

Permalink
Add gc call and empty cache to rag disposal
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Esser <[email protected]>
  • Loading branch information
florianesser-tng committed Dec 2, 2024
1 parent 9a82532 commit 9fcacb7
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions service/rag.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import gc
import json
from typing import Any, List, Dict
import torch
import time
import os
import re
import aipg_utils as utils
import model_config
from langchain_core.embeddings import Embeddings
import time
from typing import Any, List, Dict

# from sentence_transformers import SentenceTransformer
import intel_extension_for_pytorch as ipex # noqa: F401
import torch
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.document_loaders.markdown import UnstructuredMarkdownLoader
from langchain_community.document_loaders.pdf import PyPDFLoader
from langchain_community.document_loaders.text import TextLoader
from langchain_community.document_loaders.word_document import (
UnstructuredWordDocumentLoader,
Docx2txtLoader,
)
from langchain_community.document_loaders.markdown import UnstructuredMarkdownLoader
from langchain_community.document_loaders.pdf import PyPDFLoader
from langchain_community.document_loaders.text import TextLoader
from langchain_community.vectorstores.faiss import FAISS, Document

# from sentence_transformers import SentenceTransformer
import intel_extension_for_pytorch as ipex # noqa: F401
from langchain_core.embeddings import Embeddings
from sentence_transformers import SentenceTransformer

import aipg_utils as utils
import model_config

#### CONFIGURATIONS ------------------------------------------------------------------------------------------------------------------------
INDEX_DATABASE_PATH = "./db/" # Faiss database folder
CHUNK_SIZE = 1600 # Chunk size for text spliter
Expand Down Expand Up @@ -290,3 +292,5 @@ def dispose():
del embedding_database
embedding_database = None
Is_Inited = False
gc.collect()
torch.xpu.empty_cache()

0 comments on commit 9fcacb7

Please sign in to comment.