Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MongoChatMemory ¶ added in v0.0.4
func MongoChatMemory(dbName, dbConnURL string) *mongo.Collection
initializeMongoDB sets up MongoDB collections and client
Types ¶
type ChatMemoryCollectionInterface ¶ added in v0.0.4
type ChatMemoryCollectionInterface interface { AddConversationToMemory(sessionId, prompt, aiMessage string) error RetrieveMemoryWithK(sessionId string, k int64) (string, error) }
ChatMemoryCollectionInterface defines the required methods for managing chat memory operations
type MongoCollection ¶ added in v0.0.4
type MongoCollection struct {
// contains filtered or unexported fields
}
MongoCollection implements ChatMemoryCollectionInterface
func NewMongoCollection ¶ added in v0.0.4
func NewMongoCollection(collection *mongo.Collection) *MongoCollection
NewMongoCollection creates a new MongoCollection instance
func (*MongoCollection) AddConversationToMemory ¶ added in v0.0.4
func (mc *MongoCollection) AddConversationToMemory(sessionId, prompt, aiMessage string) error
This function creates a new memory entry in a MongoDB collection.
Args:
userId (str): The user ID to associate with the memory. prompt (str): The user's prompt. ai_message (str): The AI's response message.
The function trims off a specified string from the ai_message before storing it.
func (*MongoCollection) RetrieveMemoryWithK ¶ added in v0.0.4
func (mc *MongoCollection) RetrieveMemoryWithK(sessionId string, k int64) (string, error)
This function retrieves the most recent entries from a MongoDB collection where the userId matches the provided userId. It only returns entries if they were created within the last 1 minute. If no matching entries are found, or if the most recent matching entries are older than 1 minute, the function returns None.
Args:
collection: The MongoDB collection to retrieve the memory from. userId (str): The user ID to match. k (int): The number of memory messages to pull
Returns:
list: The most recent matching entries in the collection, or None if no match is found or if the entries are older than 1 minute.
type MongoCollections ¶ added in v0.0.4
type MongoCollections struct { ChatMemory *mongo.Collection Mu sync.RWMutex // contains filtered or unexported fields }
var (
Collections MongoCollections
)