From 4565934720ef5fd4869d78fc0acd5c34a7e0de3e Mon Sep 17 00:00:00 2001
From: "Embruch, Gerd" <gerd.embruch@uni-hamburg.de>
Date: Thu, 25 Jul 2024 15:51:35 +0200
Subject: [PATCH] finished embeddings/remove & embeddings/update ; dropped
 unnecessary embeddings/create

---
 __tests__/manualREST/rag.rest |  7 -------
 controllers/Embeddings.js     |  6 +++---
 routes/embeddings.js          | 39 ++++++++++++++++++++++++++---------
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/__tests__/manualREST/rag.rest b/__tests__/manualREST/rag.rest
index e636245..8289ea1 100644
--- a/__tests__/manualREST/rag.rest
+++ b/__tests__/manualREST/rag.rest
@@ -51,10 +51,3 @@ GET {{host}}/embeddings
 Authorization: Bearer {{token}}
 Accept: application/json
 Content-Type: application/json
-
-### createEmbeddings
-# @name createEmbeddings
-PUT {{host}}/embeddings
-Authorization: Bearer {{token}}
-Accept: application/json
-Content-Type: application/json
diff --git a/controllers/Embeddings.js b/controllers/Embeddings.js
index cf485a0..01e701b 100644
--- a/controllers/Embeddings.js
+++ b/controllers/Embeddings.js
@@ -60,7 +60,7 @@ export const retriever = vectorStoreConnection.asRetriever();
 /** *******************************************************
  * REMOVE VECTOR DB
  */
-export const removeVectorDb = async (req, res) => {
+export const removeVectorDb = async (req, res, next) => {
   // check if vDB is running
   const vectorDBrunning = await isVectorDbAvailable();
   // exit if not running
@@ -83,7 +83,7 @@ export const removeVectorDb = async (req, res) => {
 /** *******************************************************
  * CHECK STATUS OF VECTOR DB
  */
-export const getStatus = async (req, res) => {
+export const getStatus = async (req, res, next) => {
   // check if vDB is running
   const vectorDBrunning = await isVectorDbAvailable();
   // exit if not running
@@ -133,7 +133,7 @@ export const createEmbeddings = async (req, res) => {
 /** *******************************************************
  * UPDATE EMBEDDINGS
  */
-export const updateEmbeddings = async (req, res) => {
+export const updateEmbeddings = async (req, res, next) => {
   // check if collection is available
   const collection = await isCollectionAvailable();
   if (!collection) {
diff --git a/routes/embeddings.js b/routes/embeddings.js
index 11db9c7..3882339 100644
--- a/routes/embeddings.js
+++ b/routes/embeddings.js
@@ -6,19 +6,38 @@ import { gateKeeper } from "../controllers/Auth.js";
 
 const router = Router();
 
-// remove Vector DB
-// router.delete('/', verifyAccessToken, gateKeeper, removeVectorDb);
-
-// Vector DB status
+/**
+ * REMOVE VECTOR DB
+ * deletes the whole vector DB collection
+ *
+ * @header  {authorization}  Bearer       [required] access token
+ *
+ * @return  {object}                     related message
+ */
+router.delete('/', verifyAccessToken, gateKeeper, removeVectorDb);
+
+/**
+ * VECTOR DB STATUS
+ * creates vector DB collection if not exists
+ * returns the status of the vector DB
+ *
+ * @header  {authorization}  Bearer       [required] access token
+ *
+ * @return  {object}                     information about the vector DB collection
+ */
 router.get('/', verifyAccessToken, gateKeeper, getStatus);
 
-// createEmbeddings
-// router.put('/', pbVerifyAccessToken, gateKeeper, createEmbeddings);
-
 // update embeddings
-// TODO test update & delete https://python.langchain.com/v0.1/docs/integrations/vectorstores/chroma/#update-and-delete
-// https://js.langchain.com/v0.1/docs/integrations/vectorstores/chroma/#usage-delete-docs
-// router.patch('/', pbVerifyAccessToken, gateKeeper, updateEmbeddings);
+/**
+ * UPDATE EMBEDDINGS
+ * removes orphaned and outdates embeddings
+ * inserts updated and brand new embeddings
+ *
+ * @header  {authorization}  Bearer       [required] access token
+ *
+ * @return  {object}                     information about the update
+ */
+router.patch('/', verifyAccessToken, gateKeeper, updateEmbeddings);
 
 
 
-- 
GitLab