Skip to main content

AI-powered document indexing helping title companies

New utilization of conversational AI (artificial intelligence) and large language models (LLM) in document indexing by Columbus, Ohio-based Razi Title is already providing new efficiency for clients. In an exclusive interview with The Title Report, Razi Title Chief Technology Officer Robert Zwink outlined these additions to his company’s platform, which were made in December. “In our experience, there’s generally always a backlog of paperwork via title plants or data warehouses or starter management systems,” he said. “It all seems to lead back to there being a stack of paper everywhere. In order to streamline that, you have to know what you’re working with. “The ability to use AI to classify documents right down to the page level can help clear out those stacks.As we clear out paperwork, there’s a consumer benefit. When you think about the wait that can happen, or the variability in closings, it’s often a stack of paperwork that you have to get through. AI can streamline operations an...

Tech Tip: Managing Your Test Environment with PostgreSQL Stored Procedures

Greetings from the tech trenches! I'm the CTO of Razi Title, Inc., a tech startup pushing the envelope of what's possible in our industry. As any tech team knows, maintaining a clean and reliable testing environment is an essential aspect of our daily operations. The ability to quickly set up, tear down, and refresh our testing data is critical for ensuring our software's quality and reliability. Today, I wanted to share some tricks we've developed using PostgreSQL stored procedures to facilitate this process.


In PostgreSQL, a stored procedure allows us to encapsulate and store complex SQL queries for later execution. In our case, we have created two stored procedures - `truncate_tables` and `copy_data` - that, when used in tandem, ensure we have a fresh and reliable testing environment ready for action.


Truncating Tables: `truncate_tables`


Our first stored procedure, `truncate_tables`, is a workhorse in our test data management toolkit. It loops through all tables in a given schema and truncates them, effectively wiping all data and preparing for a fresh test run.


Here is the code:



CREATE OR REPLACE PROCEDURE truncate_tables(schema_to text) AS
$$
DECLARE
    _tbl text;
BEGIN
    FOR _tbl IN
        SELECT tablename FROM pg_tables WHERE schemaname = schema_to
    LOOP
        EXECUTE format('TRUNCATE TABLE %I.%I CASCADE', schema_to, _tbl);
    END LOOP;
END;
$$ LANGUAGE plpgsql;

Once the old test data is purged, we use our second stored procedure, `copy_data`, to copy fresh data from our source schema to the test schema. This procedure is unique and somewhat nuanced, as it takes into account that the column order in the source and target tables might not be identical.


This difference in column order can occur even when both schemas have been generated by Django's `migrate` command, as Django does not enforce a specific column order. But fear not, our stored procedure handles this gracefully by explicitly specifying column names in both the `INSERT INTO` and `SELECT` statements. If a table does not exist in the target schema, it is simply skipped.


Here is the `copy_data` code:



CREATE OR REPLACE PROCEDURE copy_data(schema_from text, schema_to text) AS
$$
DECLARE
    _tbl text;
    _exists boolean;
    table_arr text[];
    i int;
BEGIN
    -- Recursive CTE to find tables in order of foreign key dependency
    WITH RECURSIVE fk_tables AS (
        -- Find tables that have no foreign keys into them (base case)
        SELECT
            tb.oid,
            tb.relname AS tablename,
            array_agg(tb.relname) AS all_tables
        FROM
            pg_class AS tb
            LEFT JOIN pg_constraint AS fk ON fk.confrelid = tb.oid
        WHERE
            tb.relkind = 'r'
            AND fk.oid IS NULL
            AND tb.relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = schema_from)
        GROUP BY
            tb.oid,
            tb.relname
        UNION ALL
        -- Recursively find tables that have a foreign key into a table we've seen
        SELECT
            tb.oid,
            tb.relname AS tablename,
            all_tables || tb.relname
        FROM
            fk_tables
            JOIN pg_constraint AS fk ON fk.conrelid = fk_tables.oid
            JOIN pg_class AS tb ON fk.confrelid = tb.oid
        WHERE
            NOT tb.relname = ANY(all_tables)
    )
    SELECT array_agg(tablename) INTO table_arr FROM fk_tables;

    FOR i IN 1 .. array_length(table_arr, 1)
    LOOP
        _tbl := table_arr[i];
        EXECUTE format('SELECT EXISTS (SELECT 1 FROM pg_tables WHERE schemaname = %L AND tablename = %L)',
                       schema_to, _tbl) INTO _exists;
        IF _exists THEN
            EXECUTE (
                SELECT
                    'INSERT INTO ' || schema_to || '.' || _tbl ||
                    ' ("' || string_agg(column_name, '", "') || '") SELECT "' ||
                    string_agg(column_name, '", "') || '" FROM ' || schema_from || '.' || _tbl || ';'
                FROM
                    information_schema.columns
                WHERE
                    table_schema = schema_from AND table_name = _tbl
                GROUP BY
                    table_schema,
                    table_name
            );
        END IF;
    END LOOP;
END;
$$ LANGUAGE plpgsql;


These two procedures have become instrumental for us to quickly and effectively manage our test environment. For instance, we can schedule them to run before every major test suite, ensuring the latest data structure and content are in place, mimicking our production environment as closely as possible.


I hope that by sharing our approach, other teams may find inspiration or at least a starting point to address similar challenges in their development process. Happy testing!


Stay tuned for more insights from the front lines of startup tech. If you have any questions or thoughts, feel free to share them in the comments below!


Best,

Rob Zwink

CTO, Razi Title, Inc.




Popular Posts

AI-powered document indexing helping title companies

New utilization of conversational AI (artificial intelligence) and large language models (LLM) in document indexing by Columbus, Ohio-based Razi Title is already providing new efficiency for clients. In an exclusive interview with The Title Report, Razi Title Chief Technology Officer Robert Zwink outlined these additions to his company’s platform, which were made in December. “In our experience, there’s generally always a backlog of paperwork via title plants or data warehouses or starter management systems,” he said. “It all seems to lead back to there being a stack of paper everywhere. In order to streamline that, you have to know what you’re working with. “The ability to use AI to classify documents right down to the page level can help clear out those stacks.As we clear out paperwork, there’s a consumer benefit. When you think about the wait that can happen, or the variability in closings, it’s often a stack of paperwork that you have to get through. AI can streamline operations an...

Conversational AI like Chat GPT has applications for title industry

As ChatGPT and similar artificial intelligence (AI) models gain popularity, title professionals from Washington, D.C.-based Razi Title, Inc. are finding ways to use those innovations to improve everyday efficiency. Razi Title Chief Technology Officer Robert Zwink and Chief Executive Officer Lili Farhandi sat down with  The Title Report  to discuss what they’ve dubbed “TitleGPT,” a conversational AI built in-house that specializes in title industry-related documentation. “We didn’t build this from total scratch,” Zwink said. “We’ve made use of the same technology that ChatGPT uses. Ours is unique, standalone and purpose-built for indexing title documents. When I first started interacting with ChatGPT, I asked if there was a word for the anxiety someone can feel in harnessing this type of technology. “Lili and I are very passionate about strengthening the title community. At the end of the day, we want to put this at the fingertips of all title professionals, distill this tech d...

Tech Tip: How Mutool Can Enhance Your Real Estate Title Operations: The Next-Level PDF Repair Tool

Hello to all of our dedicated real estate professionals, As the Chief Technology Officer of Razi, I often work with various stakeholders within the real estate industry. And what I consistently find is that we all face a common struggle: dealing with problematic PDF files. Now, before you dismiss this as a minor issue, consider the critical role that PDF files play in real estate transactions. These documents contain contracts, property details, and critical customer information. A problem with a PDF can delay a deal, create confusion, or even lead to losses. While there are numerous tools available to address these challenges, the most common choice in the industry has been Ghostscript. Don't get me wrong; Ghostscript has been an instrumental tool in handling PDFs for many years. However, we've found that it has its limitations, particularly when it comes to repairing damaged or problematic PDF files. This can be problematic for real estate title offices, where precision and a...