jupiter0913 commited on
Commit ·
eb06dca
1
Parent(s): 0ca0baa
feature(#35): change get_pinecone_index_train_namespace function path.
Browse files
Brain/src/rising_plugin/guardrails-config/actions/actions.py
CHANGED
|
@@ -48,19 +48,16 @@ from Brain.src.rising_plugin.pinecone_engine import (
|
|
| 48 |
)
|
| 49 |
|
| 50 |
|
| 51 |
-
def get_pinecone_index_train_namespace() -> str:
|
| 52 |
-
return get_pinecone_index_namespace(f"trains")
|
| 53 |
-
|
| 54 |
-
|
| 55 |
@action()
|
| 56 |
async def general_question(query):
|
| 57 |
"""step 0: convert string to json"""
|
| 58 |
index = init_pinecone(PINECONE_INDEX_NAME)
|
|
|
|
| 59 |
try:
|
| 60 |
json_query = json.loads(query)
|
| 61 |
except Exception as ex:
|
| 62 |
raise BrainException(BrainException.JSON_PARSING_ISSUE_MSG)
|
| 63 |
-
"""step 0-->: parsing
|
| 64 |
query = json_query["query"]
|
| 65 |
model = json_query["model"]
|
| 66 |
uuid = json_query["uuid"]
|
|
@@ -75,14 +72,13 @@ async def general_question(query):
|
|
| 75 |
vector=query_result,
|
| 76 |
top_k=3,
|
| 77 |
include_values=False,
|
| 78 |
-
namespace=get_pinecone_index_train_namespace(),
|
| 79 |
)
|
| 80 |
documentId = ""
|
| 81 |
if len(relatedness_data["matches"]) > 0:
|
| 82 |
documentId = relatedness_data["matches"][0]["id"]
|
| 83 |
|
| 84 |
docs = []
|
| 85 |
-
train_service = TrainService()
|
| 86 |
documents = train_service.read_all_documents()
|
| 87 |
for document in documents:
|
| 88 |
if document["document_id"] == documentId:
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
@action()
|
| 52 |
async def general_question(query):
|
| 53 |
"""step 0: convert string to json"""
|
| 54 |
index = init_pinecone(PINECONE_INDEX_NAME)
|
| 55 |
+
train_service = TrainService()
|
| 56 |
try:
|
| 57 |
json_query = json.loads(query)
|
| 58 |
except Exception as ex:
|
| 59 |
raise BrainException(BrainException.JSON_PARSING_ISSUE_MSG)
|
| 60 |
+
"""step 0-->: parsing params from the json query"""
|
| 61 |
query = json_query["query"]
|
| 62 |
model = json_query["model"]
|
| 63 |
uuid = json_query["uuid"]
|
|
|
|
| 72 |
vector=query_result,
|
| 73 |
top_k=3,
|
| 74 |
include_values=False,
|
| 75 |
+
namespace=train_service.get_pinecone_index_train_namespace(),
|
| 76 |
)
|
| 77 |
documentId = ""
|
| 78 |
if len(relatedness_data["matches"]) > 0:
|
| 79 |
documentId = relatedness_data["matches"][0]["id"]
|
| 80 |
|
| 81 |
docs = []
|
|
|
|
| 82 |
documents = train_service.read_all_documents()
|
| 83 |
for document in documents:
|
| 84 |
if document["document_id"] == documentId:
|
Brain/src/service/train_service.py
CHANGED
|
@@ -23,10 +23,10 @@ def to_json(page_content: str):
|
|
| 23 |
|
| 24 |
|
| 25 |
class TrainService:
|
| 26 |
-
"""train (getting embedding) and update pinecone with embeddings by
|
| 27 |
train datatype:
|
| 28 |
-
key:
|
| 29 |
-
values: {
|
| 30 |
|
| 31 |
def __init__(self):
|
| 32 |
self.db = firestore.client()
|
|
@@ -115,3 +115,6 @@ class TrainService:
|
|
| 115 |
|
| 116 |
def get_pinecone_index_namespace(self) -> str:
|
| 117 |
return get_pinecone_index_namespace(f"trains")
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
class TrainService:
|
| 26 |
+
"""train (getting embedding) and update pinecone with embeddings by document_id
|
| 27 |
train datatype:
|
| 28 |
+
key: document_id
|
| 29 |
+
values: {page_content}"""
|
| 30 |
|
| 31 |
def __init__(self):
|
| 32 |
self.db = firestore.client()
|
|
|
|
| 115 |
|
| 116 |
def get_pinecone_index_namespace(self) -> str:
|
| 117 |
return get_pinecone_index_namespace(f"trains")
|
| 118 |
+
|
| 119 |
+
def get_pinecone_index_train_namespace(self) -> str:
|
| 120 |
+
return get_pinecone_index_namespace(f"trains")
|