Update rag_llamaindex.py
Browse files- rag_llamaindex.py +15 -2
rag_llamaindex.py
CHANGED
@@ -5,6 +5,7 @@ from llama_index import download_loader, PromptTemplate, ServiceContext
|
|
5 |
from llama_index.embeddings import OpenAIEmbedding
|
6 |
from llama_index.indices.vector_store.base import VectorStoreIndex
|
7 |
from llama_index.llms import OpenAI
|
|
|
8 |
from llama_index.storage.storage_context import StorageContext
|
9 |
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
|
10 |
|
@@ -14,7 +15,7 @@ from rag_base import BaseRAG
|
|
14 |
|
15 |
class LlamaIndexRAG(BaseRAG):
|
16 |
MONGODB_DB_NAME = "llamaindex_db"
|
17 |
-
|
18 |
def load_documents(self):
|
19 |
docs = []
|
20 |
|
@@ -102,5 +103,17 @@ class LlamaIndexRAG(BaseRAG):
|
|
102 |
service_context = self.get_service_context(config),
|
103 |
similarity_top_k = config["k"]
|
104 |
)
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
return query_engine.query(prompt)
|
|
|
5 |
from llama_index.embeddings import OpenAIEmbedding
|
6 |
from llama_index.indices.vector_store.base import VectorStoreIndex
|
7 |
from llama_index.llms import OpenAI
|
8 |
+
from llama_index.prompts import LangchainPromptTemplate
|
9 |
from llama_index.storage.storage_context import StorageContext
|
10 |
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
|
11 |
|
|
|
15 |
|
16 |
class LlamaIndexRAG(BaseRAG):
|
17 |
MONGODB_DB_NAME = "llamaindex_db"
|
18 |
+
|
19 |
def load_documents(self):
|
20 |
docs = []
|
21 |
|
|
|
103 |
service_context = self.get_service_context(config),
|
104 |
similarity_top_k = config["k"]
|
105 |
)
|
106 |
+
|
107 |
+
###
|
108 |
+
prompt_template = LangchainPromptTemplate(
|
109 |
+
template = os.environ["RAG_TEMPLATE"],
|
110 |
+
template_var_mappings = {"context": "context",
|
111 |
+
"question": "question"},
|
112 |
+
)
|
113 |
+
|
114 |
+
query_engine.update_prompts(
|
115 |
+
{"response_synthesizer:text_qa_template": prompt_template}
|
116 |
+
)
|
117 |
+
###
|
118 |
+
|
119 |
return query_engine.query(prompt)
|