Skip to content

Commit

Permalink
feat: return result when upserting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrueger12 committed Sep 29, 2024
1 parent 787a614 commit 6d292bd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
11 changes: 10 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@

SemCache is an open-source semantic cache microservice for LLM applications. SemCache is aimed at advanced LLM application developers looking for a secure, performant semantic cache for their applications.


## Why Use SemCache?
SemCache abstracts away the complexity of semantic cache by packing the configuration of the database and API routes into a simple endpoint.

### When to use SemCache
SemCache fills the need for lightweight tools that provide core functionality without the bloat of the existing libraries. SemCache is built with cloud native deployments in mind.
SemCache fills the need for lightweight tools that provide core functionality without the bloat of the existing libraries. SemCache is built with cloud native deployments in mind.

## Endpoints

`/check` - Checks if there is any data in the cache
`/write` - Upserts data in the cache
4 changes: 2 additions & 2 deletions database/qdrant_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func GetQdrant(client *qdrant.Client, vectors []float32) ([]GetOutputJSON, error
return outputData, err
}

func PutQdrant(client *qdrant.Client, vectors []float32, message string, modelResponse string) *qdrant.UpdateResult {
func PutQdrant(client *qdrant.Client, vectors []float32, message string, modelResponse string) qdrant.UpdateStatus {
id, _ := uuid.NewRandom()

// Upsert some data
Expand Down Expand Up @@ -162,5 +162,5 @@ func PutQdrant(client *qdrant.Client, vectors []float32, message string, modelRe
}
fmt.Println("Upsert", len(upsertPoints), "points")

return operationInfo
return operationInfo.GetStatus()
}
16 changes: 6 additions & 10 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type PutRequestBody struct {
}

type PutResponseBody struct {
Result string `json:"operation_result"`
Result string `json:"result"`
}

func HandleGetRequest(c *fiber.Ctx) error {
Expand Down Expand Up @@ -113,7 +113,6 @@ func HandleGetRequest(c *fiber.Ctx) error {

func HandlePutRequest(c *fiber.Ctx) error {
c.Accepts("text/plain", "application/json")
c.Accepts("json", "text")

// Parse the JSON body using Sonic
var reqBody PutRequestBody
Expand All @@ -126,7 +125,7 @@ func HandlePutRequest(c *fiber.Ctx) error {

log.Info().Msgf("Received request body: %v", reqBody)

// Execute a couple of steps (example operations)
// convert to lowercase
reqBody.Message = strings.ToLower(reqBody.Message)

log.Info().Msgf("Converted message to lowercase: %v", reqBody.Message)
Expand All @@ -139,22 +138,19 @@ func HandlePutRequest(c *fiber.Ctx) error {

log.Info().Msg("Created vectors for query")

// query qdrant for response
// initialize databases
// Acess Qdrant client
qdrantClient := database.GetQdrantClient()

log.Info().Msg("Initialized Qdrant client")

operationInfo := database.PutQdrant(qdrantClient, vectors, reqBody.Message, reqBody.ModelResponse)

log.Info().Msgf("Received operation info: %v", operationInfo)
log.Info().Msgf("received operation info: %v", operationInfo)

// Prepare the response
respBody := PutResponseBody{
Result: "operationInfo",
Result: operationInfo.String(),
}

// Encode the response using Sonic
// Encode the response
jsonResp, err := c.App().Config().JSONEncoder(respBody)
if err != nil {
log.Error().Msg("Failed to encode response")
Expand Down

0 comments on commit 6d292bd

Please sign in to comment.