File size: 951 Bytes
7d9087b
e50c54a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from langchain_community.vectorstores import FAISS

def format_docs(docs):
    return "\n\n".join(doc.page_content for doc in docs)

def create_vector_store(splits, embeddings):
    vectorstore = FAISS.from_documents(splits, embeddings)
    return vectorstore

def retrive_vector_store(retriever, query):
    retrieved_docs = retriever.invoke(query)
    return format_docs(retrieved_docs)

def generate_prompt(context="", question=""):
    return f""""You are DocChatAI, a helpful AI assistant built by Deepak7376.
                If the user provides context, use it to answer the question.
                If no context is provided, rely on general knowledge.
                If you don't know the answer, say you don't know. 
                Keep the answer concise.\n\n
                "Context: <start_context> {context} </end_context>"

                Human: {question}

                Assistance: Let's think step by step.
                """