Nueva publicación

查找

Ten en cuenta que esta publicación está obsoleta.
InterSystems Official
· 18 sep, 2023

Sep. 18, 2023 – Alert: Failed login handling and OAuth2 client errors

InterSystems has corrected two defects regarding connectivity. These defects and their corrections are independent of each other.

This alert addresses them both because there are point releases containing both corrections.

Both defects only impact versions 2019.1.4 and 2020.1.4 of:

  • InterSystems IRIS®
  • InterSystems IRIS for Health
  • HealthShare® Health Connect

Neither defect impacts any released version of HealthShare Unified Care Record®, Information Exchange, Health Insight, Patient Index, Provider Directory, Care Community, Personal Community, or Healthcare Action Engine.

The first defect causes failed login attempts to hang for 60 seconds before returning. The correction reduces this to two seconds and provides a better notification message. The correction is identified as DP-421918.

The second defect causes a <PROTECT> error in OAuth2 clients configured on an InterSystems IRIS instance in /csp/sys/oauth2/OAuth2.JWTServer.cls. The correction is identified as DP-418534.

InterSystems has replaced the original distributions with point releases to make these corrections available on an expedited basis. The relevant version identifiers are:

 Original posting  Point Release
 2019.1.4.755.0  2019.1.4.756.1
 2020.1.4.536.0  2020.1.4.538.1

The corrections are also available via Ad hoc distribution. 

If you have any questions regarding this alert, please contact the Worldwide Response Center.

Comentarios (0)1
Inicie sesión o regístrese para continuar
Artículo
· 18 sep, 2023 Lectura de 5 min

InterSystems IRIS Flask Generative AI application


Hi Community

In this article, I will introduce my application IRIS-GenLab.

IRIS-GenLab is a generative AI Application that leverages the functionality of Flask web framework, SQLALchemy ORM, and InterSystems IRIS to demonstrate Machine Learning, LLM, NLP, Generative AI API, Google AI LLM, Flan-T5-XXL model, Flask Login and OpenAI ChatGPT use cases.

Application Features

  • User registration and authentication
  • Chatbot functionality with the help of Torch (python machine learning library)
  • Named entity recognition (NER), natural language processing (NLP) method for text information extraction
  • Sentiment analysis, NLP approch that identifies the emotional tone of the message
  • HuggingFace Text generation with the help of GPT2 LLM (Large Language Model) model and Hugging Face pipeline
  • Google PALM API, to access the advanced capabilities of Google’s large language models (LLM) like PaLM2
  • Google Flan-T5 XXL, a fine-tuned on a large corpus of text data that was not filtered for explicit contents.
  • OpenAI is a private research laboratory that aims to develop and direct artificial intelligence (AI)


Application Flow

Python app.py file import 

#import genlab application
from genlab import create_app
from genlab.myconfig import *
from flaskext.markdown import Markdown

if __name__ == "__main__":
    # get db info from config file
    database_uri = f'iris://{DB_USER}:{DB_PASS}@{DB_URL}:{DB_PORT}/{DB_NAMESPACE}'
    # Invokes create_app function
    app = create_app(database_uri)
    Markdown(app)
    #Run flask application on 4040 port
    app.run('0.0.0.0', port="4040", debug=False)

The above code invokes create_app() function and then runs the application on port 4040

create_app() function is defined in __init__.py file, which create/modify database and initilize views

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from .myconfig import *

#init SQLAlChemy reference
db = SQLAlchemy()

def create_app(database_uri):
    app = Flask(__name__)
    app.config['SECRET_KEY'] = "iris-genlab"
    # Getting DB parameters from myconfig.py file
    app.config['SQLALCHEMY_DATABASE_URI'] = database_uri
    app.app_context().push()

    from .views import views
    from .auth import auth
    from .models import User
    #register blueprints
    app.register_blueprint(views, url_prefix="/")
    app.register_blueprint(auth, url_prefix="/")
    #init datbase
    db.init_app(app)
    with app.app_context():
        db.create_all()

    # Assign Login View
    login_manager = LoginManager()
    login_manager.login_view = "auth.login"
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(id):
        return User.query.get(int(id))

    return app

The above code creates the database by invoking SQLAlchemy create_all() function which will create user table based on structure defined in the models.py file

from . import db
from flask_login import UserMixin
from sqlalchemy.sql import func

#User table
class User(db.Model, UserMixin):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(150), unique=True)
    username = db.Column(db.String(150), unique=True)
    password = db.Column(db.String(150))
    date_created = db.Column(db.DateTime(timezone=True), default=func.now())
    def __repr__(self):
        return f'{self.username}'


Named entity recognition (NER)

Named entity recognition with spaCy, a open-source library for Natural Language Processing (NLP) in Python
Navigate to to http://localhost:4040/ner, enter text and click on submit button to view the results

image

Above URL invoces ner() methon from views.py file

from flask import Blueprint, render_template, request
from flask_login import login_required, current_user
from spacy import displacy
import spacy


HTML_WRAPPER = """<div style="overflow-x: auto; border: 1px solid #e6e9ef; border-radius: 0.25rem; padding: 1rem">{}</div>"""
views = Blueprint("views", __name__)

#Named Entitiy Recognition
@views.route('/ner', methods=["GET", "POST"])
@login_required
def ner():
     if request.method == 'POST':            
            raw_text = request.form['rawtext']
            result = ''
            if len(raw_text.strip()) > 0:
               # Load English tokenizer, tagger, parser and NER
               nlp = spacy.load('en_core_web_sm')
               docx = nlp(raw_text)
               html = displacy.render(docx, style="ent")
               html = html.replace("\n\n", "\n")
               result = HTML_WRAPPER.format(html)
               return render_template('ner.html', user=current_user, result=result,rawtext = raw_text, pst=True )
        
     return render_template('ner.html', user=current_user, pst=False)

Below is the ner.html template file which inhertied from base.html

{% extends "base.html" %} {% block title %}Home{% endblock %} 

{% block head %}
      <h2 class="display-4">Named entity recognition</h2>
      <p>with spaCy, a open-source library for Natural Language Processing (NLP) in Python</p>
{% endblock %}


{% block content %}
<form method="POST">
	<textarea rows="7" required="true" name="rawtext" class="form-control txtarea-main">
		{{ rawtext }}
	</textarea>
	<button type="submit" class="btn btn-info"><i class="fa fa-database"></i> Submit</button>
	<a class="btn btn-primary waves-effect" href="/" role="button"> <i class="fa fa-eraser"></i> Refresh</a>
</form>
{% if pst %}
{% filter markdown %}
{% endfilter %}
<hr/>
          <div class="card shadow-sm" id="custom_card2">
          	<h4>Result</h4>
			<p>{{ result|markdown }}</p>
		</div>
{% endif %}
{% endblock %}

 

Application Database

SQLALchemy will create below tables:

  • user: To store User information

To view table details, navigate to http://localhost:52775/csp/sys/exp/%25CSP.UI.Portal.SQL.Home.zen?$NAMESPACE=USER#
image

For more details please visit IRIS-GenLab open exchange application page

Thanks

Comentarios (0)1
Inicie sesión o regístrese para continuar
Artículo
· 18 sep, 2023 Lectura de 7 min

Vectors support, well almost

Nowadays so much noise around LLM, AI, and so on. Vector databases are kind of a part of it, and already many different realizations for the support in the world outside of IRIS. 

Why Vector?

  • Similarity Search: Vectors allow for efficient similarity search, such as finding the most similar items or documents in a dataset. Traditional relational databases are designed for exact match searches, which are not suitable for tasks like image or text similarity search.
  • Flexibility: Vector representations are versatile and can be derived from various data types, such as text (via embeddings like Word2Vec, BERT), images (via deep learning models), and more.
  • Cross-Modal Searches: Vectors enable searching across different data modalities. For instance, given a vector representation of an image, one can search for similar images or related texts in a multimodal database.

And many other reasons.

So, for this pyhon contest, I decided to try to implement this support. And unfortunately I did not manage to finish it in time, below I'll explain why.

There are a few major things, that have to be done, to make it full

  • Accept and store vectorized data, with SQL, simple example, (3 in this example is the amount of dimensions, it's fixed per field, and all vectors in the field have to have exact dimensions)
    create table items(embedding vector(3));
    insert into items (embedding) values ('[1,2,3]');
    insert into items (embedding) values ('[4,5,6]');
    
  • Similarity functions, there are different algorithms for similarity, suitable for a simple search on a small amount of data, without using indexes
    -- Euclidean distance
    select embedding, vector.l2_distance(embedding, '[9,8,7]') distance from items order by distance;
    -- Cosine similarity
    select embedding, vector.cosine_distance(embedding, '[9,8,7]') distance from items order by distance;
    -- Inner product
    select embedding, -vector.inner_product(embedding, '[9,8,7]') distance from items order by distance;
  • Custom index, which helps with a faster search on a big amount of data, indexes can use a different algorithm, and use different distance functions from above, and some other options
    • HNSW
    • Inverted file index
  • The search just will use the created index and its algorithm will find the requested information.

Insert vectors

The vector is expected to be an array of numeric values, which could be integers or floats, as well as signed or not. In IRIS we can store it just as $listbuild, it has a good representation, it's already supported, only needed to implement conversion from ODBC to logical.

Then the values can be inserted as plain text using external drivers such as ODBC/JDBC or from just inside IRIS with ObjectScript

  • Plain SQL
    insert into items (embedding) values ('[1,2,3]');
  • From ObjectScript
    set rs = ##class(%SQL.Statement).%ExecDirect(, "insert into test.items (embedding) values ('[1,2,3]')")
    
    set rs = ##class(%SQL.Statement).%ExecDirect(, "insert into test.items (embedding) values (?)", $listbuild(2,3,4))
    
  • Or Embedded SQL
    &sql(insert into test.items (embedding) values ('[1,2,3]'))
    
    set val = $listbuild(2,3,4)
    &sql(insert into test.items (embedding) values (:val))

It will always be stored as $lb(), and returned back in textual format in ODBC

 
Unexpected behaviour

Calculations

Mainly vectors are required to support the calculation of distances between two vectors

For the contest, I needed to use embedded Python, and here comes an issue, how to operate with $lb in Embedded Python. There is a method ToList in %SYS.Class, but Python package iris does not have it builtin, and needs to call it ObjectScript way

ClassMethod l2DistancePy(v1 As dc.vector.type, v2 As dc.vector.type) As %Decimal(SCALE=10) [ Language = python, SqlName = l2_distance_py, SqlProc ]
{
    import iris 
    import math
    
    vector_type = iris.cls('dc.vector.type')
    v1 = iris.cls('%SYS.Python').ToList(vector_type.Normalize(v1))
    v2 = iris.cls('%SYS.Python').ToList(vector_type.Normalize(v2))

    return math.sqrt(sum([(val1 - val2) ** 2 for val1, val2 in zip(v1, v2)]))
}

It does not look right at all. I would prefer that $lb could be interpreted on a fly as list in python, or at list builtin functions to_list and from_list

Another issue is when I tried to test this function using different ways. Using SQL from Embedded Python that uses SQL Function written in Embedded Python, it will crash. So, I had to add ObjectScript's functions as well.

ModuleNotFoundError: No module named 'dc'
SQL Function VECTOR.NORM_PY failed with error:  SQLCODE=-400,%msg=ERROR #5002: ObjectScript error: <OBJECT DISPATCH>%0AmBm3l0tudf^%sqlcq.USER.cls37.1 *python object not found

Currently implemented functions to calculate distance, both in Python and ObjectScript

  • Euclidean distance
    [SQL]_system@localhost:USER> select embedding, vector.l2_distance_py(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+----------------------+
    | embedding | distance             |
    +-----------+----------------------+
    | [4,5,6]   | 5.91607978309961613  |
    | [1,2,3]   | 10.77032961426900748 |
    +-----------+----------------------+
    2 rows in set
    Time: 0.011s
    [SQL]_system@localhost:USER> select embedding, vector.l2_distance(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+----------------------+
    | embedding | distance             |
    +-----------+----------------------+
    | [4,5,6]   | 5.916079783099616045 |
    | [1,2,3]   | 10.77032961426900807 |
    +-----------+----------------------+
    2 rows in set
    Time: 0.012s
  • Cosine similarity
    [SQL]_system@localhost:USER> select embedding, vector.cosine_distance(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+---------------------+
    | embedding | distance            |
    +-----------+---------------------+
    | [4,5,6]   | .034536677566264152 |
    | [1,2,3]   | .11734101007866331  |
    +-----------+---------------------+
    2 rows in set
    Time: 0.034s
    [SQL]_system@localhost:USER> select embedding, vector.cosine_distance_py(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+-----------------------+
    | embedding | distance              |
    +-----------+-----------------------+
    | [4,5,6]   | .03453667756626421781 |
    | [1,2,3]   | .1173410100786632659  |
    +-----------+-----------------------+
    2 rows in set
    Time: 0.025s
  • Inner product
    [SQL]_system@localhost:USER> select embedding, vector.inner_product_py(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+----------+
    | embedding | distance |
    +-----------+----------+
    | [1,2,3]   | 46       |
    | [4,5,6]   | 118      |
    +-----------+----------+
    2 rows in set
    Time: 0.035s
    [SQL]_system@localhost:USER> select embedding, vector.inner_product(embedding, '[9,8,7]') distance from items order by distance;
    +-----------+----------+
    | embedding | distance |
    +-----------+----------+
    | [1,2,3]   | 46       |
    | [4,5,6]   | 118      |
    +-----------+----------+
    2 rows in set
    Time: 0.032s

Additionally Implemented mathematical functions, add, sub, div, mul. InterSystems support create own aggregate functions. So, it could be possible to sum all vectors or find the avg. But unfortunately, InterSystems does not support using the same name and needs use own name (and schema) for function. But it does not support non-numeric result for aggregate function

Simple vector_add function, which returns a sum of two vectors

When used as an aggregate, it shows 0, while the expected vector too

Build an index

Unfortunately, I did not manage to finish this part, due to some obstacles I faced during realization. 

  • The lack of builtin $lb to python list conversions and back when vector in IRIS stored in $lb, and all the logic with building index is expected to be in Python, it's important to get data from $lb and set it back to globals too
  • lack of support for globals 
    • $Order in IRIS, supports direction, so it can be used in reverse, while order realization in Python Embedded does not have it, so it will require reading all keys and reversing them or storing the end somewhere
  • Have doubts due to bad experience with Python's SQL functions, called from Python mentioned above
  • During the building index, was expected to store distances in the graph between vectors, but faced a bug with storing float numbers in global

I opened 11 issues with Embedded Python I found during the work, so most of the time to find workarounds to solve issues. With help from @Guillaume Rongier project named iris-dollar-list I managed to solve some issues.

Installation

Anyway it is still available and can be installed with IPM, and used even with limited functionality 

zpm "install vector"

Or in development mode with docker-compose

git clone https://github.com/caretdev/iris-vector.git
cd iris-vector
docker-compose up -d
7 comentarios
Comentarios (7)5
Inicie sesión o regístrese para continuar
Artículo
· 17 sep, 2023 Lectura de 2 min

Enhanced Password Management: Edit Passwords Seamlessly

Enhanced Password Management: Edit Passwords Seamlessly

In the ever-evolving landscape of digital security, robust password management tools have become indispensable. Our password management application, designed to simplify and secure your online life, now comes with an enhanced feature – the ability to edit passwords with ease.

Why is this feature a game-changer?

  1. Flexibility: Life is dynamic, and so are our online accounts. With the new edit password feature, you have the flexibility to modify your saved passwords whenever you need to. Whether you want to change a password due to security concerns or simply update it, this feature allows you to adapt effortlessly.
  2. Streamlined Experience: Editing passwords is seamless and user-friendly. No more tedious processes or creating new entries from scratch. Just a few clicks, and your password is updated, keeping your records organized and up-to-date.
  3. Enhanced Security: We prioritize security above all else. The edit password functionality ensures that your updated password is encrypted using your existing encryption key. This means that even when modifying passwords, your data remains protected.
  4. Personalization: Your passwords, your way. Customize titles, logins, and passwords as needed. This feature enables you to make your password manager truly personal, fitting your unique preferences and organization style.

How it works:

  • Log in to your account.
  • Navigate to the password you want to edit.
  • Click the 'Edit' icon.
  • Modify the password title, login, or password itself.
  • Save your changes.
  • Your updated password is now securely stored and ready to use.

Stay Secure, Stay Organized:

With the enhanced edit password feature, our password manager offers an even more comprehensive solution for your security needs. Stay secure, stay organized, and manage your passwords with confidence.

What's Next:

Our commitment to improving your digital security experience doesn't stop here. We are continuously working on enhancing our password manager with new features and capabilities. Stay tuned for more updates and innovations as we strive to make your online life simpler and more secure.

Try out the edit password feature today and experience the convenience of effortless password management.

Comentarios (0)1
Inicie sesión o regístrese para continuar
Pregunta
· 14 sep, 2023

How to do a SQL query in DTL and map PV1 7.1 to results of query

I need to run a SQL query and use the output to map PV1 7.1. The query is :

SELECT ID
FROM TestTable
WHERE ProviderName = 'TEST,PROVIDER' AND IDType= 'BPI'

 

When I run this query with the 'TEST PROVIDER'  I do pull the ID in question but I can't figure out how to do it from the DTL given that there are various providers sent in PV 1 7 . Any assistance will be greatly appreciated. 

8 comentarios
Comentarios (8)2
Inicie sesión o regístrese para continuar