发布新帖

查找

问题
· 五月 15, 2024

Embeded python : Can I create a dict from COS?

Hi, I need to use some pythonic library from cos.
To use them I need a python dict with some python object in it
Ex in python:

obj = pythonObject("value1")
dict = {object : obj  ,key : "value2"}
result = pythonFunc(dict)

To do that I first tried to pass by dynamic object, to later convert them in dict from Json. But unfortunately the dynamic object doesn't accept python object inside it. And my pythonic function need to have an instance of my python object.
So I tried with the python built-in function dict() to create a python dictionary, but I'm not sure how to use it as in the python documentation I need to do dict(key1 = value1, key2 = value2).
Is it possible to create dict in COS using embeded python or if there is another way?

2 Comments
讨论 (2)1
登录或注册以继续
文章
· 五月 15, 2024 阅读大约需 4 分钟

IKO - Lecciones aprendidas (Parte 1 - Helm)

La documentación de IKO es robusta. Una única página web, que consta de unas 50 páginas reales de documentación. Para los principiantes eso puede ser un poco abrumador. Como dice el refrán: ¿cómo se come un elefante? Mordisco a mordisco. Empecemos con el primer bocado: Helm.

¿Qué es Helm?

Helm es a Kubernetes lo que el InterSystems Package Manager (IPM, antes ObjectScript Package Manager - ZPM) es a IRIS.

Facilita la instalación de aplicaciones en la plataforma, de una forma adecuada para Kubernetes. Es decir, está desarrollado de tal manera que facilita la instalación según sus necesidades, ya sea un entorno de desarrollo, prueba o producción.

Proporcionamos en nuestra distribución de software WRC todo lo que necesitaréis en la pestaña IRIS Components - consiste en un .tar.gz. Extraedlo y obtendréis un .tar. Extraedlo de nuevo y veréis una carpeta iris_operator_<versión>. Aquí hay un README con instrucciones, así como 3 carpetas - una imagen del IKO (también podríais haberla obtenido del InterSystems Container Registry), un chart y ejemplos. Los ejemplos son sólo para ayudaros a crear vuestros archivos, pero en realidad no es necesario para la instalación IKO. El chart, sin embargo, es necesario. Echemos un vistazo.

chart
|
|-> iris-operator
               |
               | -> README.md
               | -> .helmignore
               | -> Chart.yaml
               | -> values.yaml
               | -> templates 
                      | -> _helpers.tpl
                      | -> apiregistration.yaml
                      | -> appcatalog-user-roles.yaml
                      | -> cleaner.yaml
                      | -> cluster-role.yaml
                      | -> cluster-role-binding.yaml
                      | -> deployment.yaml
                      | -> mutating-webhook.yaml
                      | -> NOTES.txt
                      | -> service.yaml
                      | -> service-account.yaml
                      | -> user-roles.yaml
                      | -> validating-webhook.yaml
               

Esta es la carne y las patatas (una forma divertida de decir ingredientes básicos) de la aplicación que vamos a instalar. No os preocupéis. Lo único que nos importa es el values.yaml. Todo lo demás sucede entre bastidores, gracias a Helm. ¡Uf! Pero es importante saber que aunque nuestro operador pueda parecer un pod ordinario, es mucho más que eso.

La mayoría de los contenidos del values.yaml también van a estar fuera del alcance de este artículo porque no tendréis que preocuparos por ellos. Sólo nos preocuparemos de 4 campos (vale, 5 como mucho).

Son operator.registry, operator.repository, operator.tag, imagePullSecrets.name[0] e imagePullPolicy.

¿Dónde está vuestra imagen IKO? ¿Vuestra organización utiliza un repositorio privado? ¿Estáis planeando extraerla del ICR? Especificad los detalles de vuestra imagen en los campos de registro, repositorio y etiqueta. Si estáis utilizando el ICR podéis dejarlo como está.

¿Cómo accederéis al ICR o al repositorio de su organización? Suponiendo que sea privado, tendréis que especificar los datos con los que podréis acceder a él para tirar de él. En el próximo artículo hablaré de cómo crear este secreto, que podemos llamar intersystems-pull-secret en lugar del dockerhub-secret estándar que es lo que hay actualmente si habéis descargado los archivos del WRC.

Finalmente para el imagePullPolicy podemos dejarlo como Always, o alternativamente cambiarlo a IfNotPresent o Never. Os remito a la documentación de Kubernetes si necesitáis aclaraciones - aquí. Yo suelo usar IfNotPresent.

¡Parece que estamos listos para ir (suponiendo que ya tenéis Helm instalado, si no instaladlo primero)! Vamos a instalar el IKO. Vamos a tener que decirle a helm donde está la carpeta con todas nuestras cosas (esa es la carpeta iris-operator que veis arriba). Si estuviéramos en el directorio chart podéis usar el comando

helm install intersystems iris-operator

pero quizá estáis trabajando en algún nivel superior. No hay problema. Supongamos que estáis en un repositorio con iris_operator_amd-3.6.7.100:

helm install intersystems iris_operator_amd-3.6.7.100/chart/iris-operator

Recibiréis un mensaje que os indicará que la instalación se ha realizado correctamente y podréis comprobar que la instalación se está ejecutando tal y como se indica en el mensaje y en nuestra documentación.

kubectl --namespace=default get deployments -l "release=intersystems, app=iris-operator"

En el próximo post pondremos en práctica InterSystems Kubernetes Operator.

讨论 (0)1
登录或注册以继续
文章
· 五月 15, 2024 阅读大约需 4 分钟

IRIS/Caché SQL优化经验分享 - 优化关键字

SQL查询优化器一般情况下能给出最好的查询计划,但不是所有情况都这样,所以InterSystems SQL还提供了一个方式, 也就是在查询语句里加入optimize-option keyword(优化关键字), 用来人工的修改查询计划。

比如下面的查询:

SELECT AVG(SaleAmt) FROM %PARALLEL User.AllSales GROUP BY Region

其中的%PARALLEL, 就是最常用的优化关键字, 它强制SQL优化器使用多进程并行处理这个SQL。

您可以这样理解: 如果查询优化器足够聪明,那么绝大多数情况下,根本就不需要优化关键字来人工干预。因此,您也一定不奇怪在不同的IRIS/Caché版本中, 关键字的表现可能不一样。越新的版本,应该是越少用到。比如上面的%PARALLEL, 在Caché的大多数版本中, 在查询中加上它一般都能提高查询速度,而在IRIS中,尤其是2023版本以后, 同样的SQL查询语句,很大的可能查询优化器已经自动使用多进程并行查询了,不再需要用户人工干预了。

因此,先总结有关优化关键字的要点:

讨论 (0)1
登录或注册以继续
文章
· 五月 15, 2024 阅读大约需 3 分钟

Surveillance des environnements InterSystems IRIS avec le service Red Hat Insights

InterSystems a travaillé en étroite collaboration avec l'équipe Red Hat Insights pour mettre en œuvre un ensemble de recommandations destinées aux administrateurs de systèmes afin de garantir une expérience optimale de l'utilisation d'InterSystems IRIS sur Red Hat Enterprise Linux (RHEL).

讨论 (0)0
登录或注册以继续
文章
· 五月 15, 2024 阅读大约需 6 分钟

IRIS AI Studio: Connectors to Transform your Files into Vector Embeddings for GenAI Capabilities

In the previous article, we saw different modules in IRIS AI Studio and how it could help explore GenAI capabilities out of IRIS DB seamlessly, even for a non-technical stakeholder. In this article, we will deep dive into "Connectors" module, the one that enables users to seamlessly load data from local or cloud sources (AWS S3, Airtable, Azure Blob) into IRIS DB as vector embeddings, by also configuring embedding settings like model and dimensions. 

 

New Updates  ⛴️ 

  • Online Demo of the application is now available at https://iris-ai-studio.vercel.app
  • Connectors module can now load data from (OpenAI/Cohere embeddings)
    • Local Storage
    • AWS S3
    • Azure Blob Storage
    • Airtable
  • Playground module is fully functional with
    • Semantic Search
    • Chat with Docs
    • Recommendation Engine
      • Cohere Re-rank
      • OpenAI Re-rank
    • Similarity Engine

 

Connectors

If you have used ChatGPT 4 or other LLM services where they get the context and run the intelligence on top of that context, that ideally adds business value over a generic LLM. Simply the intelligence on your data. This module out of box gives a no-code interface to load data from different sources, do embeddings on it and load it to IRIS DB. This connectors module mainly go through 3 steps

  1. Fetching data from different sources
  2. Getting the data embedded using OpenAI/Cohere embedding models
  3. Loading the embeddings and text into IRIS DB

 

Step 1: Fetching data from different source

1. Local Storage - Upload files. I have used Llama Index's SimpleDirectoryReader to load data from files. 

(a limitation of up to 10 files in one go is put to handle the load on tiny server that I used for demo purpose. Can be negated on your own implementation)

# Check for uploaded files
if "files" not in request.files:
  return jsonify({"error": "No files uploaded"}), 400
uploaded_files = request.files.getlist("files")
if len(uploaded_files) > 10:
  return jsonify({"error": "Exceeded maximum file limit (10)"}), 400
temp_paths = []
for uploaded_file in uploaded_files:
  fd, temp_path = tempfile.mkstemp()
  with os.fdopen(fd, "wb") as temp:
    uploaded_file.save(temp)
  temp_paths.append(temp_path)

# Load data from files
documents = SimpleDirectoryReader(input_files=temp_paths).load_data()

 

 2. AWS S3

Input Parameters: Client ID, Client Secret and Bucket Name. You may get the client id and secret from the AWS console - IAM or creating read permissions for your bucket over there.

I have used "s3fs" library to fetch the contents from AWS S3 and Llama Index's SimpleDirectoryReader to load data from the fetched files.

access_key = request.form.get('aws_access_key')
secret = request.form.get('aws_secret')
bucket_name = request.form.get('aws_bucket_name')

if not all([access_key, secret, bucket_name]):
    return jsonify({"error": "Missing required AWS S3 parameters"}), 400
s3_fs = S3FileSystem(key=access_key, secret=secret)
reader = SimpleDirectoryReader(input_dir=bucket_name, fs=s3_fs, recursive=True)
documents = reader.load_data()

 

3. Airtable

Input Parameters: Token (API Key), Base ID and Table ID. API Key can be retrieved from the Airtable's Developer Hub. Base ID and Table ID can be found from the table's URL. The one that starts with "app.." is the base ID and "tbl.." is the Table ID

I have used Airtable Reader from LlamaHub to fetch the contents from Airtable and Llama Index's SimpleDirectoryReader to load data from the fetched files.

airtable_token = request.form.get('airtable_token')
table_id = request.form.get('table_id')
base_id = request.form.get('base_id')

if not all([airtable_token, table_id, base_id]):
        return jsonify({"error": "Missing required Airtable parameters"}), 400
reader = AirtableReader(airtable_token)
documents = reader.load_data(table_id=table_id, base_id=base_id)

 

4. Azure Blob Storage: 

Input Parameters: Container name and Connection string. These information can be retrieved from Azure's AD page. 

I have used AzStorageBlob Reader from LlamaHub to fetch the contents from Azure Storage and Llama Index's SimpleDirectoryReader to load data from the fetched files.

container_name = request.form.get('container_name')
connection_string = request.form.get('connection_string')

if not all([container_name, connection_string]):
    return jsonify({"error": "Missing required Azure Blob Storage parameters"}), 400
loader = AzStorageBlobReader(
    container_name=container_name,
    connection_string=connection_string,
)
documents = loader.load_data()

LlamaHub does contain 500+ connectors ranging from different file types to services. Adding a new connector based on your needs should be pretty straight forward. 

 

Step 2: Getting the data embedded using OpenAI/Cohere embedding models

Embeddings are numerical representations that capture the semantics of text, enabling applications like search and similarity matching. Ideally the objective is, when an user asks a question, its embedding is compared to document embeddings using methods like cosine similarity – higher similarity indicates more relevant content. 

Here, I'm using llama-iris library to store embeddings into IRIS DB. In the IRISVectorStore params

  • Connection String is needed for interaction with DB
    • For trying out in the online demo version, you may not use a locally running instance (localhost).
    • You would need an IRIS instance that runs on AWS/Azure/GCP with 2024.1+ version, since those support vector storage and retrieval.
    • The IRIS Community instance provided by the learning hub seems to be running with 2022.1 version, in which case that cannot be used for exploration purpose.
  • Table Name is the one that will be used to create or update records into
    • The library "llama-iris" appends "data_" to the table name. So, when you are trying to check the data through DB client, append "data_" to the table name. Say, you've named table as "users", you would need to retrieve as "data_users"
  • Embed Dim / Embedding Dimension is the dimension of the Embedding model that the user used
    • Say you've loaded "users" table by using OpenAI embeddings - "text-embedding-3-small" with 1536 dimension. You would be able to load more data into the table, but only with 1536 dimension. Same goes with vector embedding retrievals as well. So, make sure to choose the right model in the initial phases.
CONNECTION_STRING = f"iris://{username}:{password}@{hostname}:{port}/{namespace}"
vector_store = IRISVectorStore.from_params(
    connection_string=CONNECTION_STRING,
    table_name=table_name,
    embed_dim=embedding_dimension
)

Settings.embed_model = set_embedding_model(indexing_type, model_name, api_key)

storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
    documents,
    storage_context=storage_context
)

 

Step 3: Loading the embedding and text into IRIS DB

The above written code covers the indexing and loading of data into IRIS DB. Here is how the data would look like - 

Text - Raw text information that's been extracted from the files we loaded

Node ID - This would be used as a reference when we do retrievals 

Embeddings - The actual numerical representations of the text data

 

These three steps are through which the connectors module mainly work. When it comes to required data, like DB credentials and API Keys - I get it from the user and save it to the browser's local storage (Instance Details) and session storage (API Keys). It gives more modularity to the application for anyone to explore.

 

By bringing together the loading of vector-embedded data from files and the retrieval of content through various channels, IRIS AI Studio enables an intuitive way to explore the Generative AI possibilities that InterSystems IRIS offers - not only for existing customers, but also for new prospects. 

🚀 Vote for this application in Vector Search, GenAI and ML contest, if you find it promising!

If you can think of any potential applications using this implementation, please feel free to share them in the discussion thread.

2 Comments
讨论 (2)0
登录或注册以继续