DEV Community

Cover image for What is a Mind
Nguyễn Thanh Tùng
Nguyễn Thanh Tùng

Posted on

What is a Mind

Minds work similarly to large language models(LLMs) but go beyond by answering any question from any data. This is accomplished by selecting the most relevant data for an answer using parametric search, understanding the meaning and providing responses within the correct context through semantic search, and finally, delivering precise answers by analyzing data and using machine learning (ML) models.

What is Minds Ruby SDK?

https://github.com/tungnt1203/minds_ruby_sdk

Minds Ruby SDK is a Ruby library that allows you to interact with MindsDB - a platform that helps integrate machine learning and AI into your database. This SDK provides simple methods to:

  • Manage data sources (Datasources)
  • Create and manage "Minds" - trained AI models
  • Perform AI queries on your data

How to Use Minds Ruby SDK

1. Installation and Configuration

First, you need to install the gem:

gem install minds_ruby_sdk
Enter fullscreen mode Exit fullscreen mode

Then, configure the SDK with your API key:

require 'minds'

Minds::Client.configure do |config|
  config.api_key = 'your_api_key_here'
  config.base_url = 'https://mdb.ai' # or URL of your private instance
end

client = Minds::Client.new
Enter fullscreen mode Exit fullscreen mode

2. Managing Datasources

You can easily add, view, and delete data sources:

# Create a new datasource
config = Minds::Resources::DatabaseConfig.new(
  name: 'my_postgres_db',
  engine: 'postgres',
  description: 'My PostgreSQL database',
  connection_data: {
    host: 'localhost',
    port: 5432,
    user: 'username',
    password: 'password',
    database: 'my_db'
  }
)
client.datasources.create(config)

# List all datasources
all_datasources = client.datasources.all

# Find a specific datasource
my_datasource = client.datasources.find('my_postgres_db')

# Delete a datasource
client.datasources.destroy('my_postgres_db')
Enter fullscreen mode Exit fullscreen mode

see support datasources

3. Working with Minds

Minds are AI models trained on your data:

# Create a new mind
new_mind = client.minds.create(
  name: 'my_smart_mind',
  model_name: 'gpt-3.5-turbo',
  provider: 'openai',
  datasources: ['my_postgres_db'],
  prompt_template: "Answer questions about the data in my_postgres_db: {{question}}"
)
# Find a mind
my_mind = client.minds.find('my_smart_mind')

# Update a mind
my_mind.update(prompt_template: "New instructions: {{question}}")

# Delete a mind
client.minds.destroy('my_smart_mind')
Enter fullscreen mode Exit fullscreen mode

4. Completion:

response = my_mind.completion(message: "What is the total revenue for last month?")
puts response

# Or use stream mode
my_mind.completion(message: "Analyze sales trends", stream: true) do |chunk|
  puts chunk.dig("choices", 0, "delta", "content")
end
Enter fullscreen mode Exit fullscreen mode

Conclusion

Minds Ruby SDK opens up a new world for Ruby developers, allowing them to easily integrate AI into their applications. From managing data sources to creating and using AI models, this SDK provides a simple yet powerful interface for interacting with Minds.

With Minds Ruby SDK, building intelligent applications capable of answering complex questions based on your data becomes easier than ever. Experiment and explore the new possibilities this SDK brings to your projects!

Top comments (0)