redis

package
v0.29.0-beta Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 11 Imported by: 0

README

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

The Redis component is a data component 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 definition and tasks are defined in the [definition.json](https://github.com/instill-ai/component/blob/main/data/redis/v0/config/definition.json) and [tasks.json](https://github.com/instill-ai/component/blob/main/data/redis/v0/config/tasks.json) files respectively.

## Setup


In order to communicate with Redis Labs, the following connection details need to be
provided. You may specify them directly in a pipeline recipe as key-value pairs
within the component's `setup` block, or you can create a **Connection** from
the [**Integration Settings**](https://www.instill.tech/docs/vdp/integration)
page and reference the whole `setup` as `setup:
${connection.<my-connection-id>}`.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| 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.  |

</div>




## Supported Tasks

### Retrieve Chat History

Retrieve chat history from Redis.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| 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 |
</div>






<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Output | ID | Type | Description |
| :--- | :--- | :--- | :--- |
| [Chat Message](#retrieve-chat-history-chat-message) | `messages` | array[object] | Messages |
</div>

<details>
<summary> Output Objects in Retrieve Chat History</summary>

<h4 id="retrieve-chat-history-chat-message">Chat Message</h4>

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| [Content](#retrieve-chat-history-content) | `content` | array | The message content |
| Metadata | `metadata` | object | The message metadata |
| Role | `role` | string | The message role, i.e. 'system', 'user' or 'assistant' |
</div>

<h4 id="retrieve-chat-history-content">Content</h4>

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| [Image URL](#retrieve-chat-history-image-url) | `image-url` | object | The image URL |
| Text | `text` | string | The text content. |
| Type | `type` | string | The type of the content part. |
</div>

<h4 id="retrieve-chat-history-image-url">Image URL</h4>

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| Field | Field ID | Type | Note |
| :--- | :--- | :--- | :--- |
| URL | `url` | string | Either a URL of the image or the base64 encoded image data. |
</div>
</details>

### Write Chat Message

Write chat message into Redis.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| 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 |
</div>






<div class="markdown-col-no-wrap" data-col-1 data-col-2>

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

### Write Multi Modal Chat Message

Write multi-modal chat message into Redis.

<div class="markdown-col-no-wrap" data-col-1 data-col-2>

| 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 |
</div>






<div class="markdown-col-no-wrap" data-col-1 data-col-2>

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

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(bc base.Component) *component

func NewClient

func NewClient(setup *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 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

Jump to

Keyboard shortcuts

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