simcache

package module
v0.0.0-...-894307e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2024 License: MIT Imports: 2 Imported by: 0

README

simcache

Semantic cache for your LLM apps in Go!

Usage of simcache via LangchainGo and Upstash

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/semioz/simcache"
	"github.com/tmc/langchaingo/llms"
	"github.com/tmc/langchaingo/llms/openai"
	"github.com/upstash/vector-go"
)

func main() {
	index := vector.NewIndex("UPSTASH_URL", "UPSTASH_TOKEN")
	simCache := simcache.NewSimCache(simcache.UpstashOptions{
		Index:        index,
		MinProximity: 0.9,
	})

	ctx := context.Background()
	llm, err := openai.New()
	if err != nil {
		log.Fatal(err)
	}
	prompt := "What are the some vector databases that I can use?"
	response, err := llms.GenerateFromSinglePrompt(ctx, llm, prompt)

	simCache.Set(prompt, response)

	result, err := simCache.Get("List some vector databases I can use when building a project")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PgOptions

type PgOptions struct{}

type PgSimCache

type PgSimCache struct{}

type UpstashOptions

type UpstashOptions struct {
	MinProximity float32 `json:"minProximity"`
	Index        *vector.Index
}

type UpstashSimCache

type UpstashSimCache struct {
	// contains filtered or unexported fields
}

func NewSimCache

func NewSimCache(config UpstashOptions) *UpstashSimCache

func (*UpstashSimCache) BulkDelete

func (cache *UpstashSimCache) BulkDelete(keys []string) error

func (*UpstashSimCache) Delete

func (cache *UpstashSimCache) Delete(key string) error

func (*UpstashSimCache) Flush

func (cache *UpstashSimCache) Flush() error

func (*UpstashSimCache) Get

func (cache *UpstashSimCache) Get(keyOrKeys interface{}) (interface{}, error)

func (*UpstashSimCache) Set

func (cache *UpstashSimCache) Set(keyOrKeys interface{}, valueOrValues interface{}) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL