redis

package
v0.15.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 13 Imported by: 0

README

---
title: "Redis"
lang: "en-US"
draft: false
description: "Learn about how to set up a VDP Redis connector https://github.com/instill-ai/instill-core"
---

The Redis component is a data connector that allows users to manage data in NoSQL Redis databases.
It can carry out the following tasks:

- [Retrieve Chat History](#retrieve-chat-history)
- [Write Chat Message](#write-chat-message)
- [Write Multi Modal Chat Message](#write-multi-modal-chat-message)

## Release Stage

`Alpha`

## Configuration

The component configuration is defined and maintained [here](https://github.com/instill-ai/component/blob/main/pkg/connector/redis/v0/config/definition.json).

## Connection

| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| Host (required) | `host` | string | Redis host to connect to |
| Port (required) | `port` | integer | Port of Redis |
| Username | `username` | string | Username associated with Redis |
| Password | `password` | string | Password associated with Redis |
| SSL Connection | `ssl` | boolean | Indicates whether SSL encryption protocol will be used to connect to Redis. It is recommended to use SSL connection if possible. |
| SSL Configuration | `ssl_mode` | object | SSL connection modes.    <b>verify-full</b> - This is the most secure mode. Always require encryption and verifies the identity of the source database server |

## Supported Tasks

### Retrieve Chat History

Retrieve chat history from Redis.

| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_RETRIEVE_CHAT_HISTORY` |
| Session ID (required) | `session_id` | string | A unique identifier for the chat session |
| Latest K | `latest_k` | integer | The number of latest conversation turns to retrieve. A conversation turn typically includes one participant speaking or sending a message, and the other participant(s) responding to it. |
| Include System Message If Exists | `include_system_message` | boolean | Include system message in the retrieved conversation turns if exists |

| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Chat Message | `messages` | array[object] | Messages |

### Write Chat Message

Write chat message into Redis.

| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_WRITE_CHAT_MESSAGE` |
| Session ID (required) | `session_id` | string | A unique identifier for the chat session |
| Role (required) | `role` | string | The message role, i.e. 'system', 'user' or 'assistant' |
| Content (required) | `content` | string | The message content |
| Metadata | `metadata` | object | The message metadata |

| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Status | `status` | boolean | The status of the write operation |

### Write Multi Modal Chat Message

Write multi-modal chat message into Redis.

| Input | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Task ID (required) | `task` | string | `TASK_WRITE_MULTI_MODAL_CHAT_MESSAGE` |
| Session ID (required) | `session_id` | string | A unique identifier for the chat session |
| Role (required) | `role` | string | The message role, i.e. 'system', 'user' or 'assistant' |
| Content (required) | `content` | string | The multi-modal message content |
| Metadata | `metadata` | object | The message metadata |

| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| Status | `status` | boolean | The status of the write operation |

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLatestK is the default number of latest conversation turns to retrieve
	DefaultLatestK = 5
)

Functions

func Init

func Init(l *zap.Logger, u base.UsageHandler) *connector

func NewClient

func NewClient(config *structpb.Struct) (*goredis.Client, error)

NewClient creates a new redis client

func WriteNonSystemMessage

func WriteNonSystemMessage(client *goredis.Client, sessionID string, message MultiModalMessageWithTime) error

func WriteSystemMessage

func WriteSystemMessage(client *goredis.Client, sessionID string, message MultiModalMessageWithTime) error

WriteSystemMessage writes system message for a given session ID

Types

type ChatHistoryRetrieveInput

type ChatHistoryRetrieveInput struct {
	SessionID            string `json:"session_id"`
	LatestK              *int   `json:"latest_k,omitempty"`
	IncludeSystemMessage bool   `json:"include_system_message"`
}

type ChatHistoryRetrieveOutput

type ChatHistoryRetrieveOutput struct {
	Messages []*MultiModalMessage `json:"messages"`
	Status   bool                 `json:"status"`
}

ChatHistoryReadOutput is a wrapper struct for the messages associated with a session ID

func RetrieveSessionMessages

func RetrieveSessionMessages(client *goredis.Client, input ChatHistoryRetrieveInput) ChatHistoryRetrieveOutput

RetrieveSessionMessages retrieves the latest K conversation turns from the Redis list for the given session ID

type ChatMessageWriteInput

type ChatMessageWriteInput struct {
	SessionID string `json:"session_id"`
	Message
}

type ChatMessageWriteOutput

type ChatMessageWriteOutput struct {
	Status bool `json:"status"`
}

type ChatMultiModalMessageWriteInput

type ChatMultiModalMessageWriteInput struct {
	SessionID string `json:"session_id"`
	MultiModalMessage
}

type DisableSSL

type DisableSSL struct {
	Mode SSLMode `json:"mode"`
}

DisableSSL is the struct for disable SSL

func (*DisableSSL) GetConfig

func (d *DisableSSL) GetConfig() (*tls.Config, error)

type Message

type Message struct {
	Role     string                  `json:"role"`
	Content  string                  `json:"content"`
	Metadata *map[string]interface{} `json:"metadata,omitempty"`
}

type MessageWithTime

type MessageWithTime struct {
	Message
	Timestamp int64 `json:"timestamp"`
}

type MultiModalContent

type MultiModalContent struct {
	Type     string  `json:"type"`
	Text     *string `json:"text,omitempty"`
	ImageURL *struct {
		URL string `json:"url"`
	} `json:"image_url,omitempty"`
}

type MultiModalMessage

type MultiModalMessage struct {
	Role     string                  `json:"role"`
	Content  []MultiModalContent     `json:"content"`
	Metadata *map[string]interface{} `json:"metadata,omitempty"`
}

type MultiModalMessageWithTime

type MultiModalMessageWithTime struct {
	MultiModalMessage
	Timestamp int64 `json:"timestamp"`
}

func RetrieveSystemMessage

func RetrieveSystemMessage(client *goredis.Client, sessionID string) (bool, *MultiModalMessageWithTime, error)

RetrieveSystemMessage gets system message based on a given session ID

type SSLMode

type SSLMode string

SSLMode is the type for SSL mode

const (
	DisableSSLMode    SSLMode = "disable"
	VerifyFullSSLMode SSLMode = "verify-full"
)

type SSLModeConfig

type SSLModeConfig interface {
	GetConfig() (*tls.Config, error)
}

SSLConfig is the interface for SSL configuration

type VerifyFullSSL

type VerifyFullSSL struct {
	Mode       SSLMode `json:"mode"`
	CaCert     string  `json:"ca_cert"`
	ClientCert string  `json:"client_cert"`
	ClientKey  string  `json:"client_key"`
}

VerifyFullSSL is the struct for verify-full SSL. It always requires encryption and verification of the identify of the server.

func (*VerifyFullSSL) GetConfig

func (e *VerifyFullSSL) GetConfig() (*tls.Config, error)

Jump to

Keyboard shortcuts

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