vector datatable code added

This commit is contained in:
sumedh
2024-08-07 12:13:47 +05:30
parent ab71752489
commit bee1dad131
9 changed files with 115 additions and 11 deletions

View File

@@ -0,0 +1,42 @@
package com.olympus.apollo.controllers.FeApi;
import com.olympus.apollo.dto.VectorStoreDetails;
import com.olympus.apollo.models.VectorStore;
import com.olympus.apollo.repository.VectorStoreRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/fe-api/vector-store")
@CrossOrigin(origins = "http://localhost:5173")
public class VectorStoreController {
@Autowired
private VectorStoreRepository vectorStoreRepository;
@GetMapping("")
public List<VectorStore> getAllVectorStore(){
List<VectorStore> result = (List<VectorStore>) vectorStoreRepository.findAll();
return result;
}
@GetMapping("/{id}")
public VectorStore getVectorData(@PathVariable String id){
VectorStore result = vectorStoreRepository.findById(id).get();
return result;
}
@GetMapping("/ids")
public List<String> getAllVectorStoreIds(){
List<String> ids = vectorStoreRepository.findAllIds();
return ids;
}
@GetMapping("/details")
public List<VectorStoreDetails> getAllVectorStoreDetails(){
return vectorStoreRepository.findAllDetails();
}
}

View File

@@ -1,18 +1,13 @@
package com.olympus.apollo.controllers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.codelibs.jhighlight.fastutil.Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.olympus.apollo.models.KSDocument;
import com.olympus.apollo.models.KSIngestionInfo;
@@ -20,7 +15,7 @@ import com.olympus.apollo.repository.KSDocumentRepository;
import com.olympus.apollo.repository.KSIngestionInfoRepository;
import com.olympus.apollo.services.StorageFileNotFoundException;
import com.olympus.apollo.services.StorageService;
import com.olympus.apollo.models.FileUploadDTO;
import com.olympus.apollo.dto.FileUploadDTO;
@CrossOrigin
@RestController
public class KSFileController {
@@ -57,7 +52,7 @@ public class KSFileController {
HashMap<String, String> metadata = new HashMap<>();
metadata.put("KsApplicationName", fileUploadDTO.getKsApplicationName());
metadata.put("KsDoctype", fileUploadDTO.getKsDocType());
metadata.put("KsDocSource", fileUploadDTO.getKsDocType());
metadata.put("KsDocSource", fileUploadDTO.getKsDocSource());
metadata.put("Source", file.getOriginalFilename());
ksIngestionInfo.setMetadata(metadata);

View File

@@ -1,4 +1,4 @@
package com.olympus.apollo.models;
package com.olympus.apollo.dto;
import lombok.Getter;
import lombok.Setter;

View File

@@ -15,6 +15,4 @@ public class IngestionOutput {
public IngestionOutput(){
ingestedDocumentId=new ArrayList<String>();
}
}

View File

@@ -0,0 +1,10 @@
package com.olympus.apollo.dto;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class VectorStoreDetails {
private String id;
private VectorStoreMetadataDetails metadata;
}

View File

@@ -0,0 +1,15 @@
package com.olympus.apollo.dto;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class VectorStoreMetadataDetails {
private String KsApplicationName;
private String KsDoctype;
private String KsDocSource;
private String source;
private String Source;
}

View File

@@ -0,0 +1,20 @@
package com.olympus.apollo.models;
import lombok.Getter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.HashMap;
@Document(collection = "vector_store")
@Getter
public class VectorStore {
private @Id String id;
private HashMap<String, String> metadata;
private String content;
private String media;
private String embedding;
private HashMap<String, String> contentFormatter;
}

View File

@@ -0,0 +1,24 @@
package com.olympus.apollo.repository;
import com.olympus.apollo.dto.VectorStoreDetails;
import com.olympus.apollo.dto.VectorStoreMetadataDetails;
import com.olympus.apollo.models.VectorStore;
import org.springframework.data.mongodb.repository.Aggregation;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface VectorStoreRepository extends MongoRepository<VectorStore, String> {
@Aggregation(pipeline = {
"{ $project: { _id: 1 } }"
})
List<String> findAllIds();
@Aggregation(pipeline = {
"{ $project: { _id: 1, metadata: 1 } }"
})
List<VectorStoreDetails> findAllDetails();
}

View File

@@ -146,7 +146,7 @@ public class KSIngestor {
});
ksDocument.setIngestionStatus("INGESTED");
ksDocument.setIngestionDate(new Date());
ksDocument.setIngestionDateFormat(new SimpleDateFormat("MM/dd/yy").format(new Date()));
ksDocumentRepository.save(ksDocument);
ingestionLoopOutput.getIngestedDocumentId().add(ksDocument.getId());