Spaces:
Build error
Build error
Update rag_llamaindex.py
Browse files- rag_llamaindex.py +29 -23
rag_llamaindex.py
CHANGED
@@ -49,17 +49,10 @@ class LlamaIndexRAG(BaseRAG):
|
|
49 |
|
50 |
return docs
|
51 |
|
52 |
-
def
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
VectorStoreIndex.from_documents(
|
58 |
-
chunk_overlap = config["chunk_overlap"],
|
59 |
-
chunk_size = config["chunk_size"],
|
60 |
-
documents = docs,
|
61 |
-
#embedding = x,
|
62 |
-
storage_context = storage_context
|
63 |
)
|
64 |
|
65 |
def get_vector_store(self):
|
@@ -69,29 +62,42 @@ class LlamaIndexRAG(BaseRAG):
|
|
69 |
collection_name = self.MONGODB_COLLECTION_NAME,
|
70 |
index_name = self.MONGODB_INDEX_NAME
|
71 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
def ingestion(self, config):
|
74 |
docs = self.load_documents()
|
75 |
|
76 |
self.store_documents(config, docs)
|
77 |
-
|
78 |
-
def get_llm(self, config):
|
79 |
-
return OpenAI(
|
80 |
-
model = config["model_name"],
|
81 |
-
temperature = config["temperature"]
|
82 |
-
)
|
83 |
-
|
84 |
def retrieval(self, config, prompt):
|
85 |
-
service_context = ServiceContext.from_defaults(
|
86 |
-
llm = self.get_llm(config)
|
87 |
-
)
|
88 |
-
|
89 |
index = VectorStoreIndex.from_vector_store(
|
90 |
vector_store = self.get_vector_store()
|
91 |
)
|
92 |
|
93 |
query_engine = index.as_query_engine(
|
94 |
-
service_context =
|
95 |
similarity_top_k = config["k"]
|
96 |
)
|
97 |
|
|
|
49 |
|
50 |
return docs
|
51 |
|
52 |
+
def get_llm(self, config):
|
53 |
+
return OpenAI(
|
54 |
+
model = config["model_name"],
|
55 |
+
temperature = config["temperature"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
)
|
57 |
|
58 |
def get_vector_store(self):
|
|
|
62 |
collection_name = self.MONGODB_COLLECTION_NAME,
|
63 |
index_name = self.MONGODB_INDEX_NAME
|
64 |
)
|
65 |
+
|
66 |
+
def get_service_context(config):
|
67 |
+
return ServiceContext.from_defaults(
|
68 |
+
chunk_overlap = config["chunk_overlap"],
|
69 |
+
chunk_size = config["chunk_size"],
|
70 |
+
llm = self.get_llm(config)
|
71 |
+
)
|
72 |
+
|
73 |
+
def get_storage_context():
|
74 |
+
return StorageContext.from_defaults(
|
75 |
+
vector_store = self.get_vector_store()
|
76 |
+
)
|
77 |
+
|
78 |
+
def store_documents(self, config, docs):
|
79 |
+
storage_context = StorageContext.from_defaults(
|
80 |
+
vector_store = self.get_vector_store()
|
81 |
+
)
|
82 |
+
|
83 |
+
VectorStoreIndex.from_documents(
|
84 |
+
docs,
|
85 |
+
service_context = self.get_service_context(config),
|
86 |
+
storage_context = self.get_storage_context()
|
87 |
+
)
|
88 |
|
89 |
def ingestion(self, config):
|
90 |
docs = self.load_documents()
|
91 |
|
92 |
self.store_documents(config, docs)
|
93 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
def retrieval(self, config, prompt):
|
|
|
|
|
|
|
|
|
95 |
index = VectorStoreIndex.from_vector_store(
|
96 |
vector_store = self.get_vector_store()
|
97 |
)
|
98 |
|
99 |
query_engine = index.as_query_engine(
|
100 |
+
service_context = self.get_service_context(config),
|
101 |
similarity_top_k = config["k"]
|
102 |
)
|
103 |
|