File size: 1,016 Bytes
e54728d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS
from langchain import HuggingFacePipeline
from langchain.chains import RetrievalQA
from sentence_transformers import SentenceTransformer
import pandas as pd


from model.config.config import modelPath, model_kwargs, encode_kwargs
from model.processing.data_manager import text_chunk
from model.processing.pipeline_qa import pipeline


def embedding():
    embeddings = HuggingFaceEmbeddings(
            model_name=modelPath,
            model_kwargs=model_kwargs,
            encode_kwargs=encode_kwargs
        )
    
    return embeddings


def model(question):
    text_chunks = text_chunk()
    embeddings =embedding()

    db = FAISS.from_documents(text_chunks, embeddings)
    
    pipe = pipeline()
    
    retriever = db.as_retriever(search_kwargs={"k": 1})
    docs = retriever.get_relevant_documents(question)

    answer = pipe({
        'context': docs[0],
        'question': question})

    return answer