From 6d292bdb3a62dc95ecfebb1c88f68b050af6e5dd Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 29 Sep 2024 09:37:58 -0600 Subject: [PATCH 1/3] feat: return result when upserting --- README.MD | 11 ++++++++++- database/qdrant_client.go | 4 ++-- handlers/handlers.go | 16 ++++++---------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.MD b/README.MD index 8cd08e8..679a8e5 100644 --- a/README.MD +++ b/README.MD @@ -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. \ No newline at end of file +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 \ No newline at end of file diff --git a/database/qdrant_client.go b/database/qdrant_client.go index 2ad691e..fec8f59 100644 --- a/database/qdrant_client.go +++ b/database/qdrant_client.go @@ -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 @@ -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() } diff --git a/handlers/handlers.go b/handlers/handlers.go index 2ff8c44..6b43cfc 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -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 { @@ -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 @@ -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) @@ -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") From 2eb8950b4eb014f490a79f6d73e803534d4bc81a Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 29 Sep 2024 09:49:07 -0600 Subject: [PATCH 2/3] add publish step --- .github/workflows/publish.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/publish.yaml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..366e769 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,18 @@ +name: Publish + +on: + push: + branches: ['main', 'develop'] + +jobs: + publish: + name: Publish + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v4 + with: + go-version: '1.23.x' + - uses: actions/checkout@v3 + + - uses: ko-build/setup-ko@v0.6 + - run: ko build --platform=linux/arm64 \ No newline at end of file From 79a61fd87a00fc7f5959e4908be1b4db55d75962 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 29 Sep 2024 09:56:35 -0600 Subject: [PATCH 3/3] add publish step --- .github/workflows/publish.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 366e769..73bfa83 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -15,4 +15,6 @@ jobs: - uses: actions/checkout@v3 - uses: ko-build/setup-ko@v0.6 + env: + KO_DOCKER_REPO: ghcr.io/backland-labs/semantic-cache - run: ko build --platform=linux/arm64 \ No newline at end of file