Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: API v2 support and refactor #189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions pkg/api/base.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package api

type Tenant interface {
Name() string
String() string
}

type Database interface {
Name() string
Tenant() Tenant
String() string
}

type Include string

const (
IncludeMetadatas Include = "metadatas"
IncludeDocuments Include = "documents"
IncludeEmbeddings Include = "embeddings"
IncludeURIs Include = "uris"
IncludeIDs Include = "ids"
)

type TenantBase struct {
TenantName string `json:"name"`
}

func (t *TenantBase) Name() string {
return t.TenantName
}

func NewTenant(name string) Tenant {
return &TenantBase{TenantName: name}
}

func (t *TenantBase) String() string {
return t.Name()
}

func (t *TenantBase) MarshalJSON() ([]byte, error) {
return []byte(`"` + t.Name() + `"`), nil
}
func NewDefaultTenant() Tenant {
return NewTenant(DefaultTenant)
}

type DatabaseBase struct {
DBName string `json:"name"`
tenant Tenant
}

func (d *DatabaseBase) Name() string {
return d.DBName
}

func (d *DatabaseBase) Tenant() Tenant {
return d.tenant
}

func (d *DatabaseBase) String() string {
return d.Name()
}

func (d *DatabaseBase) MarshalJSON() ([]byte, error) {
return []byte(`"` + d.Name() + `"`), nil
}

func NewDatabase(name string, tenant Tenant) Database {
return &DatabaseBase{DBName: name, tenant: tenant}
}

func NewDefaultDatabase() Database {
return NewDatabase(DefaultDatabase, NewDefaultTenant())
}
Loading
Loading