typesense

package module
v0.61.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package typesense ranks precomputed vectors in a provisioned Typesense collection. Include SpaceField(space) beside the stored content, opaque metadata and cosine embedding fields. An index without this exact marker must be rebuilt; native automatic embedding is rejected.

Query uses native semantic ranking or native lexical/vector fusion. Supply lexical text explicitly in hybrid mode. Ordinary queries do not export the collection. Native filters on opaque Core JSON cannot guarantee equivalent results; Query therefore rejects them before model or provider I/O. QueryByScan instead requires explicit authority and a record, byte and time budget. The export and ranking calls do not share snapshot isolation.

Upsert preflights the complete batch before importing. It requests native IDs in each acknowledgment, validates them against the actual submitted keys, and keeps accepted, rejected and uncertain records distinct. An acknowledgment does not imply that a read replica can search the write.

Index

Examples

Constants

View Source
const (
	Provider                = "Typesense"
	DefaultCollectionName   = "scope_vector_store"
	DefaultMaxResponseBytes = int64(16 * 1024 * 1024)
	MaxResultsPerPage       = 250
)

Variables

View Source
var ErrIncompatibleCollection = errors.New("typesense: collection is incompatible")

Functions

func SpaceField added in v0.59.0

func SpaceField(space vectorstore.SpaceID) api.Field

SpaceField binds a provisioned collection to its immutable encoder space.

Types

type Store

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

func NewStore

func NewStore(ctx context.Context, config StoreConfig) (*Store, error)
Example
package main

import (
	"context"
	"net/http"
	"os"

	"time"

	"github.com/typesense/typesense-go/v3/typesense/api"

	"github.com/Tangerg/scope/core/document"

	"github.com/Tangerg/scope/core/vectorstore"
	"github.com/Tangerg/scope/vectorstores/typesense"
)

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
	defer cancel()
	transport := http.DefaultTransport.(*http.Transport).Clone()
	defer transport.CloseIdleConnections()
	key := os.Getenv("SCOPE_TYPESENSE_API_KEY")
	client, err := api.NewClient(os.Getenv("SCOPE_TYPESENSE_ENDPOINT"), api.WithHTTPClient(&http.Client{Transport: transport, Timeout: 30 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}), api.WithRequestEditorFn(func(_ context.Context, request *http.Request) error {
		request.Header.Set("X-TYPESENSE-API-KEY", key)
		return nil
	}))
	if err != nil {
		panic(err)
	}
	const space vectorstore.SpaceID = "encoder-v1"
	store, err := typesense.NewStore(ctx, typesense.StoreConfig{Client: client, CollectionName: "documents", Space: space})
	if err != nil {
		panic(err)
	}
	if err = store.Upsert(ctx, &vectorstore.Batch{Space: space, Records: []vectorstore.Record{{Document: &document.Document{ID: "one", Text: "example"}, Values: []float64{1, 0}}}}); err != nil {
		panic(err)
	}
	if _, err = store.Query(ctx, &vectorstore.Query{Space: space, Values: []float64{1, 0}}); err != nil {
		panic(err)
	}
	if err = store.DeleteIDs(ctx, []string{"one"}); err != nil {
		panic(err)
	}
}

func (*Store) CheckDocuments added in v0.59.0

func (s *Store) CheckDocuments(ctx context.Context, space vectorstore.SpaceID, docs []*document.Document) error

func (*Store) CheckQuery added in v0.59.0

func (s *Store) CheckQuery(ctx context.Context, space vectorstore.SpaceID, opts vectorstore.SearchOptions) error

func (*Store) DeleteIDs added in v0.43.0

func (s *Store) DeleteIDs(ctx context.Context, ids []string) error

func (*Store) Query added in v0.59.0

func (*Store) QueryByScan added in v0.60.0

QueryByScan explicitly authorizes an export of the entire collection to compute exact membership. MaxBytes bounds the JSONL source payload, not ANN pages. The collection can change between export and ranking; membership is rechecked.

func (*Store) Upsert added in v0.59.0

func (s *Store) Upsert(ctx context.Context, batch *vectorstore.Batch) error

type StoreConfig

type StoreConfig struct {
	Client           APIClient
	CollectionName   string
	Space            vectorstore.SpaceID
	HybridAlpha      *float32
	MaxResponseBytes int64
}

func (StoreConfig) Validate

func (s StoreConfig) Validate() error

Jump to

Keyboard shortcuts

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