<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title>Reference Architecture for AI</title>
      <link>https://reference-architecture.ai</link>
      <description>Reference architecture patterns for production AI agent systems. Harness engineering, context architecture, execution guardrails, and memory infrastructure.</description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://reference-architecture.ai/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Sat, 07 Nov 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>From AI Risk to Accountable Agents</title>
          <pubDate>Sat, 07 Nov 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/from-ai-risk-to-accountable-agents/</link>
          <guid>https://reference-architecture.ai/posts/from-ai-risk-to-accountable-agents/</guid>
          <description xml:base="https://reference-architecture.ai/posts/from-ai-risk-to-accountable-agents/">&lt;p&gt;In &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.linkedin.com/pulse/ai-risk-evolving-every-day-david-hunt-ziqbe/&quot;&gt;AI Risk is evolving, every day.&lt;/a&gt;, David Hunt and I examined how an AI agent can pursue a legitimate objective through methods outside its mandate. Oversight needs to connect organisational intent, knowledge, authority, actions and consequences.&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This article summarises &lt;a href=&quot;https://reference-architecture.ai/posts/organisational-roles-as-agent-contracts/&quot;&gt;the full paper&lt;/a&gt;. To supervise that agent, we need to specify its responsibilities, the concepts it uses, the evidence its work requires and the actions it may take.&lt;/p&gt;
&lt;h2 id=&quot;start-with-an-organisational-role&quot;&gt;Start with an organisational role&lt;/h2&gt;
&lt;p&gt;“Planning agent” tells us what an agent does, but leaves its responsibility unclear.&lt;/p&gt;
&lt;p&gt;A Product Manager breaks outcomes into features and acceptance criteria. A Project Manager turns agreed scope into a delivery plan with dependencies, owners and milestones. Both perform planning, but their work products and authority differ.&lt;/p&gt;
&lt;p&gt;An agent&#39;s planning capability should belong to a defined organisational role. Its implementation provides services that use tools to perform specific actions.&lt;/p&gt;
&lt;p&gt;The chain becomes:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Organisation → role → capability → service → tool → action → contextual permission.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A Project Manager agent might select an approved planning template and create a draft in its assigned project. That assignment does not authorise production deployment. The permission decision must govern the actual tool operation, including alternative routes through shells or delegated agents.&lt;/p&gt;
&lt;h2 id=&quot;give-the-role-a-defined-conceptual-space&quot;&gt;Give the role a defined conceptual space&lt;/h2&gt;
&lt;p&gt;Each role needs a governed view of organisational knowledge. A Product Manager works with user needs, value hypotheses and acceptance criteria. A Project Manager needs dependencies, resources, risks and delivery commitments. Shared concepts connect their work without making the roles interchangeable.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/diagrams/accountable-agents-01-role-and-authority.png&quot; alt=&quot;Role-based knowledge graphs connect organisational responsibilities to capabilities, services and tool actions. In the proposed architecture, the Project Manager may create a plan draft but cannot deploy to production.&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Figure 1. Proposed role contract: the knowledge needed to plan and the authority to act are explicit.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Terraphim&#39;s role-based knowledge graphs make this vocabulary explicit through concepts and synonyms. The inspected indexer connects consecutive recognised concepts in document text, retaining supporting document references. Those associations help retrieve relevant notes and explain why they were selected.&lt;/p&gt;
&lt;p&gt;The next layer is to type the relationships. A connection might mean “depends on”, “addresses a requirement” or “requires approval”. The role selects the applicable relationship profile from approved templates, traced to adopted standards or documented organisational extensions.&lt;/p&gt;
&lt;p&gt;A sentence mentioning a release, a manager and approval does not establish that approval occurred. &lt;strong&gt;“Requires approval” and “was approved” are different claims.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;verify-meaning-in-its-context&quot;&gt;Verify meaning in its context&lt;/h2&gt;
&lt;p&gt;A checklist can recognise every expected concept while missing a change in meaning.&lt;/p&gt;
&lt;p&gt;Suppose a delivery plan must place a rollback rehearsal in staging, with its planned start within eight elapsed hours of a defined failure trigger. An output can contain “rollback”, “rehearsal” and “hours” while moving the activity to production or replacing elapsed hours with business days.&lt;/p&gt;
&lt;p&gt;Successful checking therefore requires compatible concepts, relationships and context across the input, output and criteria. Different terminology can be acceptable through an explicit mapping. Changed scope, units, conditions or prohibitions cannot pass silently.&lt;/p&gt;
&lt;p&gt;Our paper uses &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.iso.org/standard/74393.html&quot;&gt;ISO/IEC/IEEE 42010:2022&lt;/a&gt; to frame architecture descriptions and &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.iso.org/standard/72089.html&quot;&gt;ISO/IEC/IEEE 29148:2018&lt;/a&gt; to distinguish requirements quality and stakeholder intent from evidence about the realised system. This is a standards-informed design, not a conformity claim.&lt;/p&gt;
&lt;p&gt;The practical requirement is traceability: identify the requirement version, relevant context, applicable criterion and evidence behind each result. When those conditions change, reassess the affected findings. Unknown context should produce an indeterminate result, not an assumed pass.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/diagrams/accountable-agents-02-contextual-verification.png&quot; alt=&quot;Contextual verification compares a proposed plan with the versioned requirement and its concepts, trigger and criteria. Preserved conditions pass this planning criterion, changed conditions fail, and missing evidence leaves the result indeterminate.&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Figure 2. Proposed contextual check: passing a planning criterion neither proves the rehearsal occurred nor grants deployment authority.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;make-the-audit-concrete&quot;&gt;Make the audit concrete&lt;/h2&gt;
&lt;p&gt;Terraph, the Terraphim language, connects a role graph, a checklist and a gated action in one program. The graph and checklist compile from Markdown into constant matching automata. &lt;code&gt;embed&lt;/code&gt; identifies concepts and source spans; &lt;code&gt;text satisfies preflight&lt;/code&gt; reports which checklist items are missing.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;deploy&lt;/code&gt; verb declares the evidence it needs. Here, &lt;code&gt;engineer&lt;/code&gt; is the example role; it does not change the Project Manager’s authority:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;import std;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;role engineer from &amp;quot;kg&amp;quot;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;checklist preflight from &amp;quot;checklists/preflight.md&amp;quot;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fn deploy(plan: str, ev: Proof&amp;lt;preflight&amp;gt;) -&amp;gt; i64 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;deploy: preflight evidence present, proceeding&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return 0;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The generated verb wrapper obtains a sealed &lt;code&gt;Proof&amp;lt;preflight&amp;gt;&lt;/code&gt; through &lt;code&gt;.require()&lt;/code&gt; only when no checklist items are missing. The proof binds to the checked snapshot, available as &lt;code&gt;ev.subject&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/diagrams/accountable-agents-03-terraph-audit.png&quot; alt=&quot;Terraph uses compiled role concepts and checklist definitions to check a text snapshot. Findings with missing items cannot yield a proof; findings with no missing items can produce a sealed proof required by the gated verb.&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Figure 3. The Terraph proof gate. The example body prints a message; it does not deploy a system.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Any actual operation must use that checked snapshot and pass a separate authority check. Reopening the plan could read changed bytes. Passing the checklist cannot give a Project Manager production privileges, nor can concept coverage establish that the plan is correct.&lt;/p&gt;
&lt;p&gt;Our earlier argument calls for supervision that follows an agent&#39;s changing context. An inspectable role contract gives that supervision a defined mandate to check. A Project Manager agent can prepare a plan, preserve its requirements and record the evidence, while release authority stays with the role responsible for exercising it.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Organisational Roles as Contracts for AI Agents</title>
          <pubDate>Sat, 07 Nov 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/organisational-roles-as-agent-contracts/</link>
          <guid>https://reference-architecture.ai/posts/organisational-roles-as-agent-contracts/</guid>
          <description xml:base="https://reference-architecture.ai/posts/organisational-roles-as-agent-contracts/">&lt;h2 id=&quot;abstract&quot;&gt;Abstract&lt;/h2&gt;
&lt;p&gt;An organisational AI agent needs defined responsibilities, relevant knowledge and bounded authority. This paper proposes roles as contracts for all three. A Project Manager plans delivery; a Product Manager decomposes product outcomes into features. Each uses a governed role-based knowledge graph. Agent services realise role capabilities through tools whose actions require contextual permission. Verification and validation require compatible concepts, relationships and operating conditions across the input and evaluation criteria, with explicit mappings where views differ. A cross-check against ISO/IEC/IEEE 42010:2022 and 29148:2018 informs these distinctions without claiming conformity. Terraphim provides graph retrieval and checklists; Terraph connects concept matching to proof-gated verbs; ADF configurations define responsibilities and artefact templates. The proposed integration would allow a Project Manager agent to create a checked plan from an approved template while reserving production deployment for a separately authorised role.&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;continuing-the-argument-on-evolving-ai-risk&quot;&gt;Continuing the argument on evolving AI risk&lt;/h2&gt;
&lt;p&gt;This paper continues the argument developed by David Hunt and Alexander Mikhalev in &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.linkedin.com/pulse/ai-risk-evolving-every-day-david-hunt-ziqbe/&quot;&gt;AI Risk is evolving, every day.&lt;/a&gt;, published on 31 October 2026. Their starting concern is that an agent can pursue a legitimate objective through unauthorised methods. They connect oversight of business activity with cybersecurity and knowledge integrity, and argue that changes to agents and their surroundings can invalidate earlier assurance.&lt;/p&gt;
&lt;p&gt;Supervision needs an inspectable mandate: the organisational role, the capability being exercised, the service providing it, and the tool action requested against a particular resource. Role-based knowledge graphs provide the relevant concepts and relationships; an independently enforced permission decision determines whether the action may proceed. A Project Manager can prepare a delivery plan using approved templates while production execution remains assigned to a separately authorised role. The sections below distinguish existing components from the integration still required.&lt;/p&gt;
&lt;p&gt;A successful check needs criteria that apply to the input&#39;s meaning, obligations and operating context. Matching words cannot establish that a plan preserves a prohibition, uses the correct environment, or retains an acceptance threshold. The semantic compatibility contract developed here connects requirements, criteria and evidence through a versioned baseline and explicit mappings. Changes to that baseline trigger reassessment of affected results. The standards cross-check helps define the responsibilities and evaluation claims; it does not establish that the supervisory system has been implemented.&lt;/p&gt;
&lt;p&gt;The common concepts connect the earlier article&#39;s concerns to the mechanisms examined in this paper:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Shared concept&lt;/th&gt;&lt;th&gt;Engineering continuation in this paper&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Mandate and justified authority&lt;/td&gt;&lt;td&gt;Trace the assigned role through capability, service, tool and action to a contextual permission decision.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Knowledge integrity and context&lt;/td&gt;&lt;td&gt;Use governed concept identities, relationships and requirement baselines to preserve meaning across inputs, outputs and criteria.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Independent supervision&lt;/td&gt;&lt;td&gt;Separate the agent&#39;s proposal from the gateway&#39;s permission decision and the evidence used to assess its result.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Continued validity of assurance&lt;/td&gt;&lt;td&gt;Bind findings to the evaluated artefact, criteria and context; reassess affected claims when relevant versions change.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Learning and authority to change&lt;/td&gt;&lt;td&gt;Govern changes to role graphs, templates and policies separately from permission to perform the task.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Prediction and operational evidence&lt;/td&gt;&lt;td&gt;Keep illustrative scenarios, expected outcomes and recorded executions distinguishable; validate predictions before relying on them.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Consequences across organisational scales&lt;/td&gt;&lt;td&gt;Make resource and project scope explicit, and identify where wider consequences require escalation beyond the acting role.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;This mapping is our architectural synthesis. The examples below illustrate individual mechanisms; connecting them across systems remains engineering work.&lt;/p&gt;
&lt;h2 id=&quot;the-organisational-unit-of-agency&quot;&gt;The organisational unit of agency&lt;/h2&gt;
&lt;p&gt;“Planning agent” describes a computational activity. It does not identify who owns the outcome, which planning conventions apply, or what authority accompanies the work. The same ambiguity affects “research agent”, “review agent” and “execution agent”. These labels can be useful implementation names, but they leave organisational meaning unresolved.&lt;/p&gt;
&lt;p&gt;A Project Manager plans delivery against agreed scope, dependencies, resources and milestones. A Product Manager decomposes desired outcomes into features, evaluates value and defines acceptance criteria. Both plan, but they plan different objects, draw on different evidence, and answer to different accountabilities. An organisation should therefore delegate to an agent acting in a defined role, with planning as one of that role’s capabilities.&lt;/p&gt;
&lt;p&gt;The role contract can remain stable when an agent’s model, prompt, framework or supplier changes. A replacement implementation must demonstrate the required service behaviour and operate within the same authority boundary. Governed role definitions and capability contracts give the organisation a basis for evaluating that replacement.&lt;/p&gt;
&lt;p&gt;The central proposal is a traceable relationship:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Organisation → role → capability → service → tool → action → contextual permission.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This sequence is an explanation path, not an assertion that authority flows automatically through every edge. The organisation assigns responsibilities to roles; an agent principal is separately authorised to enact a role. Its implementation supplies services. Tools make actions technically available. Policy determines whether an exact requested action is permitted in its current context.&lt;/p&gt;
&lt;h2 id=&quot;the-organisational-semantic-layer&quot;&gt;The organisational semantic layer&lt;/h2&gt;
&lt;p&gt;The organisational semantic layer describes concepts, relationships, templates, standards and responsibilities using explicit identifiers and versioned definitions. Here, &lt;em&gt;conceptual space&lt;/em&gt; means this governed system of organisational meaning. The proposal does not require a fully implemented geometric model of human conceptual spaces.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Element&lt;/th&gt;&lt;th&gt;Organisational meaning&lt;/th&gt;&lt;th&gt;Planning example&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Role&lt;/td&gt;&lt;td&gt;A position with responsibilities and bounded authority&lt;/td&gt;&lt;td&gt;Project Manager&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Capability&lt;/td&gt;&lt;td&gt;An ability the organisation needs to achieve an outcome&lt;/td&gt;&lt;td&gt;Delivery planning&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Service&lt;/td&gt;&lt;td&gt;An accessible behaviour provided by an implementation&lt;/td&gt;&lt;td&gt;Produce a delivery plan&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Agent implementation&lt;/td&gt;&lt;td&gt;Software that provides the service while enacting an assigned role&lt;/td&gt;&lt;td&gt;Project planning agent instance&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Tool&lt;/td&gt;&lt;td&gt;A concrete interface through which work is performed&lt;/td&gt;&lt;td&gt;Template reader or document writer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Action&lt;/td&gt;&lt;td&gt;A specific operation on an identified resource&lt;/td&gt;&lt;td&gt;Create a draft plan in project workspace&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Permission&lt;/td&gt;&lt;td&gt;A policy decision over principal, role, action, resource and context&lt;/td&gt;&lt;td&gt;Draft creation allowed for the assigned project&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Evidence&lt;/td&gt;&lt;td&gt;Records supporting a decision and its observed result&lt;/td&gt;&lt;td&gt;Template version, checks and execution receipt&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;This distinction between capabilities and services is compatible with enterprise architecture’s separation of organisational behaviour from its realisation and exposed services. It is used here as an architectural vocabulary, without claiming formal compliance with an ArchiMate model. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://archimate-community.pages.opengroup.org/workgroups/archimate-101/&quot;&gt;Open Group ArchiMate 101&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A capability describes what the organisation can accomplish. It is not a permission token. Likewise, an implementation’s demonstrated competence does not grant authority. A model may understand deployment instructions while having no right to invoke a deployment endpoint.&lt;/p&gt;
&lt;p&gt;Role capabilities contribute to broader organisational capabilities. For example, an organisation’s &lt;strong&gt;Product Delivery&lt;/strong&gt; capability can depend on &lt;strong&gt;Product Discovery&lt;/strong&gt; performed by the Product Manager, &lt;strong&gt;Delivery Planning&lt;/strong&gt; performed by the Project Manager, and &lt;strong&gt;Release Assurance&lt;/strong&gt; performed by the Release Manager. The graph records these contribution relationships explicitly. Separate agent services realise the role capabilities; their combined performance supports the organisational outcome without granting each service the authority of every contributing role.&lt;/p&gt;
&lt;p&gt;Roles should also be sufficiently specific to support ownership. An organisation can assign a person or agent multiple roles, but each action should use an explicit active role and bounded assignment. Combining role knowledge for a discussion must not silently combine execution privileges.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Role&lt;/th&gt;&lt;th&gt;Dedicated conceptual view&lt;/th&gt;&lt;th&gt;Principal service&lt;/th&gt;&lt;th&gt;Example boundary&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Product Manager&lt;/td&gt;&lt;td&gt;Outcomes, user needs, features, value hypotheses and acceptance criteria&lt;/td&gt;&lt;td&gt;Produce an evidence-linked feature breakdown&lt;/td&gt;&lt;td&gt;Cannot approve production deployment&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Project Manager&lt;/td&gt;&lt;td&gt;Scope, dependencies, resources, risks and delivery milestones&lt;/td&gt;&lt;td&gt;Produce a delivery plan from an approved template&lt;/td&gt;&lt;td&gt;Can write a project draft; cannot deploy it&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Release Manager&lt;/td&gt;&lt;td&gt;Release readiness, change records, environments and rollback procedures&lt;/td&gt;&lt;td&gt;Coordinate an authorised release&lt;/td&gt;&lt;td&gt;Production action requires a separate assignment and satisfied release policy&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;These are example contracts, not universal job descriptions. The organisation owns the actual definitions and decides where responsibilities overlap.&lt;/p&gt;
&lt;h2 id=&quot;dedicated-knowledge-without-isolated-vocabularies&quot;&gt;Dedicated knowledge without isolated vocabularies&lt;/h2&gt;
&lt;p&gt;Each role receives a governed projection of organisational knowledge. This can select which concepts and relationships are available to the role, as well as how retrieval ranks them. Roles can share an underlying graph while retaining different conceptual views.&lt;/p&gt;
&lt;p&gt;Shared concepts retain shared identifiers. For example, a feature’s acceptance criteria connect product intent with delivery planning and release verification. Role-specific relationships express what matters for each responsibility: a Product Manager connects a criterion to user value; a Project Manager connects it to delivery evidence and dependencies; a Release Manager connects it to a release decision. The shared identity supports handoffs without making the roles interchangeable.&lt;/p&gt;
&lt;p&gt;Role-owned overlays can define local vocabulary, specialised relationships, approved templates and checklist requirements. Their provenance should identify the owner, source, revision and approval state. Changes to the shared definition of “accepted” require different governance from adding a convenient synonym to a role’s retrieval vocabulary.&lt;/p&gt;
&lt;p&gt;Graph projections must also respect access controls. Knowing that another team’s confidential plan exists does not authorise retrieving its contents. A role graph is a semantic view; a separately authenticated assignment and resource policy determine what information the agent may actually read.&lt;/p&gt;
&lt;p&gt;The graph is the inspectable, or white-box, component of this architecture. A reviewer can examine its concepts and relationships, the embeddings derived from them, and the definitions that shaped retrieval. This visibility neither makes the language model transparent nor establishes that the graph&#39;s contents are correct.&lt;/p&gt;
&lt;h2 id=&quot;architecture-description-and-requirements-engineering&quot;&gt;Architecture description and requirements engineering&lt;/h2&gt;
&lt;p&gt;ISO/IEC/IEEE 42010:2022 concerns architecture descriptions, including viewpoints and model kinds. It distinguishes an architecture from its description and does not prescribe an agent implementation or execution policy. In that standard, ADF means &lt;em&gt;architecture description framework&lt;/em&gt;; the ADF agent orchestration system discussed here is a different use of the acronym. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.iso.org/standard/74393.html&quot;&gt;ISO/IEC/IEEE 42010:2022&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;For this architecture, stakeholder concerns, viewpoint conventions and resulting views must remain distinguishable from organisational roles. A viewpoint establishes conventions for constructing and interpreting views that address concerns. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.iso.org/obp/ui?_escaped_fragment_=iso:std:iso-iec-ieee:24641:ed-1:v1:en&quot;&gt;ISO 24641:2023 preview&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A role can serve several stakeholder concerns and use several viewpoints. A role graph becomes useful architectural material when its concepts, relationships, conventions and intended questions are explicit. It is not automatically a viewpoint; a project plan is not automatically an architecture view. Terraph&#39;s language constructs likewise do not establish that it is a conforming architecture description language. The standards do not assign the paper&#39;s Project Manager, Product Manager or Release Manager jobs their permissions.&lt;/p&gt;
&lt;p&gt;ISO/IEC/IEEE 29148:2018 addresses requirements engineering and its information across the life cycle. Its terminology distinguishes checks on requirements from checks on the realised product or system. The following four questions must not be collapsed into a single “validation passed” label. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.iso.org/obp/ui?_escaped_fragment_=iso%3Astd%3Aiso-iec-ieee%3A29148%3Aed-2%3Av1%3Aen&quot;&gt;ISO/IEC/IEEE 29148:2018 official preview&lt;/a&gt;&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Activity&lt;/th&gt;&lt;th&gt;Question and object&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Requirements verification&lt;/td&gt;&lt;td&gt;Are the requirement statements and set well formed?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Requirements validation&lt;/td&gt;&lt;td&gt;Do those requirements express the intended stakeholder needs?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Product or system verification&lt;/td&gt;&lt;td&gt;Does the realised item fulfil its specified requirements?&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Product or system validation&lt;/td&gt;&lt;td&gt;Does it support its intended application and use?&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Each decision needs the applicable activity and evidence; an individual tool check need not perform all four. A reviewed input baseline is particularly important: an output checklist cannot retrospectively establish what the stakeholder meant.&lt;/p&gt;
&lt;p&gt;The following crosswalk is this paper&#39;s proposed design, not an ISO clause-compliance matrix:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Standards-related distinction&lt;/th&gt;&lt;th&gt;Application to the proposed agent contract&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Stakeholder concern and viewpoint&lt;/td&gt;&lt;td&gt;Name the decision owner, concern and representation conventions; bind the agent&#39;s organisational assignment separately.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;View and modelling conventions&lt;/td&gt;&lt;td&gt;Specify graph concept and relationship types, interpretation rules and correspondences between role views.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Requirement and traceability&lt;/td&gt;&lt;td&gt;Connect each obligation to its need, responsible role, input baseline, criteria, output and evidence.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Verification and validation&lt;/td&gt;&lt;td&gt;Name the checked object, the predicate or intended-use scenario, its applicable context and the decision supported.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;This is a bounded cross-check using official public material. It is neither certification nor a full-text normative clause audit. The richer semantic contract below is the paper&#39;s engineering proposal, not a claim that either standard mandates knowledge graphs or this permission scheme.&lt;/p&gt;
&lt;h2 id=&quot;semantic-compatibility-between-inputs-and-criteria&quot;&gt;Semantic compatibility between inputs and criteria&lt;/h2&gt;
&lt;p&gt;A check is meaningful only if its criteria apply to the relevant meaning and context of its input. “Release” can mean software deployment or approval of a payment; the same token need not denote the same concept. A plan for staging cannot be validated against production assumptions merely because both mention “release”. A criterion about elapsed hours cannot silently become one about business days. Evaluation requires compatible conceptual spaces, not identical wording or complete identity between two role graphs.&lt;/p&gt;
&lt;p&gt;The proposed trace is:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Requirement ID and revision → stakeholder need → responsible role and relevant viewpoints → input concepts, propositions and context baseline → verification criterion and validation scenario → evidence → decision.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The baseline identifies the entity and project, source and requirement revisions, environment, relevant time and calendar, units and thresholds, assumptions, exceptions and prohibited actions. A proposition preserves who must do what to which object, under which conditions, with its polarity and quantifiers. “Every accepted feature” and “some features” can share concepts while imposing different obligations.&lt;/p&gt;
&lt;p&gt;Verification and validation may use different abstractions. A product view can describe a customer outcome while a delivery view describes work packages. Their mapping must explain how the relevant obligation survives decomposition and which evidence supports it. Approved unit conversions and concept mappings may establish compatibility; fuzzy similarity alone cannot. Additional derived criteria can be legitimate when their rationale and relationship to the stakeholder need are recorded. An obligation cannot disappear merely because a role projection omits its vocabulary.&lt;/p&gt;
&lt;p&gt;This paper proposes the following contract. These SHALL statements are authored requirements for the proposed integration, not quotations from ISO:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;A check SHALL identify its object, requirement baseline, applicable criteria and relevant context revisions.&lt;/strong&gt; The requirement owner and authority to resolve ambiguity or change the baseline must be recorded.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A transformation SHALL preserve relevant obligations or carry an explicitly approved mapping or change.&lt;/strong&gt; This includes relationships, polarity, quantifiers, units, thresholds, scope and assumptions, not just concept identifiers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A decision SHALL distinguish pass, fail, indeterminate and justified not applicable.&lt;/strong&gt; Missing context, unresolved mappings or insufficient evidence cannot yield a pass; not applicable needs a recorded reason and authorised acceptance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A result SHALL bind to the evaluated state and be reassessed when a relevant change invalidates it.&lt;/strong&gt; Passing semantic or quality checks never substitutes for an action&#39;s separate authority decision.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Context compatibility is necessary but insufficient. A perfectly aligned test can still have a weak predicate, unreliable evidence or inadequate coverage. Criteria must themselves be verified and validated for their purpose; their evaluation must establish the promised claim. Checks should report only what their evidence supports.&lt;/p&gt;
&lt;h2 id=&quot;connecting-meaning-with-authority&quot;&gt;Connecting meaning with authority&lt;/h2&gt;
&lt;p&gt;The architecture needs four cooperating parts: identity and assignment, semantic knowledge, mediated execution, and audit evidence.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/diagrams/roles-contract-architecture.png&quot; alt=&quot;Proposed architecture: organisational ownership and authenticated assignment, role knowledge, services, execution gateway, contextual policy, registered actions and decision evidence.&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Figure 1. Connecting meaning with authority. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://mermaid.live/edit#base64:eyJjb2RlIjogImZsb3djaGFydCBURFxuICAgIE9bT3JnYW5pc2F0aW9uIGFuZCBhY2NvdW50YWJsZSByb2xlIG93bmVyXSAtLT4gUltWZXJzaW9uZWQgcm9sZSBhbmQgY2FwYWJpbGl0eSBjb250cmFjdF1cbiAgICBJW0F1dGhlbnRpY2F0ZWQgYWdlbnQgcHJpbmNpcGFsXSAtLT4gQVtTY29wZWQgcm9sZSBhc3NpZ25tZW50XVxuICAgIFIgLS0+IEtbUm9sZSBrbm93bGVkZ2UgZ3JhcGggYW5kIGFwcHJvdmVkIHRlbXBsYXRlc11cbiAgICBSIC0tPiBTW0FnZW50IHNlcnZpY2UgY29udHJhY3RdXG4gICAgQSAtLT4gR1tFeGVjdXRpb24gZ2F0ZXdheV1cbiAgICBLIC0tPiBQW0FnZW50IHByZXBhcmVzIGEgcHJvcG9zZWQgYWN0aW9uXVxuICAgIFMgLS0+IFBcbiAgICBQIC0tPiBHXG4gICAgUVtDb250ZXh0dWFsIHBlcm1pc3Npb24gcG9saWN5XSAtLT4gR1xuICAgIEcgLS0+IFRbUmVnaXN0ZXJlZCB0b29sIGFjdGlvbl1cbiAgICBHIC0tPiBFW0RlY2lzaW9uIGFuZCBleGVjdXRpb24gZXZpZGVuY2VdXG4gICAgVCAtLT4gRVxuIiwgIm1lcm1haWQiOiB7InRoZW1lIjogImRlZmF1bHQifX0=&quot;&gt;Open the diagram source in Mermaid Live&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Role-based access control provides a foundation: subjects are assigned authorised roles, and operations are mediated through the permissions of those roles. A session can activate a subset of the roles available to a subject. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://csrc.nist.gov/Projects/role-based-access-control/faqs&quot;&gt;NIST RBAC&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The proposed architecture adds organisational meaning to this assignment and applies contextual conditions to execution. Project identity, resource scope, environment, approval state and expiry can all matter. This is consistent with attribute-based access control, which evaluates attributes of the subject, object, operation and environment against policy. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://csrc.nist.gov/pubs/sp/800/162/upd2/final&quot;&gt;NIST SP 800-162&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let a request be &lt;code&gt;q = (principal, role, service, tool, action, resource, arguments, context)&lt;/code&gt;. A simplified decision rule is:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;permit(q) =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    authenticated(principal)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND active_assignment(principal, role, scope, expiry)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND capability_service_binding(role, service)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND registered_service_tool_action(service, tool, action)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND resource_and_argument_scope_match(q)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND required_evidence_valid_for_exact_request(q)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND contextual_policy_allows(q)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AND NOT explicit_deny(q)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An absent or indeterminate condition produces no permit. This is a proposed contract, not a description of a policy engine already supplied by Terraphim.&lt;/p&gt;
&lt;p&gt;The gateway must mediate actual effects. Hiding a deployment tool in a user interface is insufficient if the same principal can deploy through a shell, network client or overprivileged service credential. The action boundary includes alternative routes, delegated agents and mutable resource references. A delegate receives only an authorised subset of the parent’s scope; it cannot turn a planning request into a production privilege.&lt;/p&gt;
&lt;h2 id=&quot;terraphim-graph-embeddings-as-a-role-context-mechanism&quot;&gt;Terraphim graph embeddings as a role context mechanism&lt;/h2&gt;
&lt;p&gt;Terraphim’s graph approach supplies a concrete semantic mechanism for the role view. Concepts and surface forms are represented explicitly, and graph relationships support retrieval and explanation. Its documented graph retrieval path uses normalised concepts, synonym matching and document co-occurrence structure, rather than requiring a neural vector embedding model. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.ai/docs/graph-embeddings/&quot;&gt;Terraphim graph embeddings&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The inspected general &lt;code&gt;RoleGraph&lt;/code&gt; implementation uses Aho–Corasick matching to resolve surface forms to concept identifiers. Its document indexer creates edges between consecutive recognised concepts in the indexed text and retains supporting document references. Retrieval then accumulates node, edge and document rank. Matched edges and tags make the retrieval basis inspectable. A high rank indicates retrieval support under that graph, not factual certainty or authority.&lt;/p&gt;
&lt;p&gt;For organisational planning, this allows terms such as “delivery roadmap” and “project plan” to resolve according to the organisation’s chosen vocabulary. The interpretation is role-dependent: a delivery roadmap may emphasise dependencies and milestones for a Project Manager, while a product roadmap emphasises outcomes and prioritisation.&lt;/p&gt;
&lt;p&gt;The organisation should keep equivalence and relationship separate. A synonym maps a surface form to a concept. A relationship links distinct concepts. “Risk log” may be an agreed synonym for “risk register”, but a register and an individual risk remain distinct concepts. “Risk” and “deployment permission” must not become equivalent merely because they occur together in operational documents.&lt;/p&gt;
&lt;p&gt;Graph embeddings make the retrieval context reproducible. A result can identify the recognised concept and supporting relationship evidence, explaining why a planning template or dependency policy was selected. Template currency, the truth of retrieved claims and action authority require separate checks against authoritative metadata, evidence and policy.&lt;/p&gt;
&lt;h3 id=&quot;from-co-occurrence-to-typed-organisational-relationships&quot;&gt;From co-occurrence to typed organisational relationships&lt;/h3&gt;
&lt;p&gt;The existing concept vocabulary and the associations found in text play different parts in constructing the role&#39;s conceptual space. The role&#39;s thesaurus supplies the concepts that can be recognised and the synonyms that resolve to them. Indexing identifies occurrences of those concepts in notes and documents, then constructs connections from the matching text. Retrieval uses that structure to select relevant material. In this path, a connection is discovered between recognised concepts; it does not establish a new concept definition or a new organisational rule.&lt;/p&gt;
&lt;p&gt;Sentence-level co-occurrence provides an intuitive starting assumption: concepts mentioned together may be related. The inspected implementation has a broader boundary. The document indexer takes the matching concept sequence from the indexed document and connects adjacent matches without invoking the available sentence-splitting helper. Associations can therefore cross sentence boundaries. A sentence-bounded association rule would require an explicit indexing change; it is not a current guarantee.&lt;/p&gt;
&lt;p&gt;Even within one sentence, proximity leaves the relationship unspecified. A note can mention a requirement and a test because the test satisfies it, fails it, or has not yet been performed. The association graph cannot decide which statement holds. The proposed semantic layer must establish the connection&#39;s meaning, direction and conditions before admitting it as a typed organisational claim.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Layer&lt;/th&gt;&lt;th&gt;Representation&lt;/th&gt;&lt;th&gt;What it establishes&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Role vocabulary&lt;/td&gt;&lt;td&gt;Canonical concepts and approved synonyms&lt;/td&gt;&lt;td&gt;Which concept a recognised expression denotes within the role&#39;s domain.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Text association&lt;/td&gt;&lt;td&gt;Connections between matched concepts, with document evidence&lt;/td&gt;&lt;td&gt;Where concepts occur together or in the indexed matching sequence.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Organisational interpretation&lt;/td&gt;&lt;td&gt;Typed, contextual propositions governed by role templates&lt;/td&gt;&lt;td&gt;Whether a connection expresses a dependency, responsibility, requirement, evidence claim or other admitted meaning.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Evaluation and execution&lt;/td&gt;&lt;td&gt;Applicable criteria, evidence checks and permission decisions&lt;/td&gt;&lt;td&gt;Whether the specific claim is supported and whether the requested action is authorised.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The organisational semantic layer supplies the relationship vocabulary. A role selects an applicable profile of that vocabulary, together with the templates for its work products. A Project Manager&#39;s delivery-plan template may admit dependencies between milestones and assignments of responsibility. A Product Manager&#39;s feature template may admit derivation from stakeholder needs and links to acceptance criteria. Shared concepts retain their identities across these views; the role determines which governed relationships are relevant, rather than inventing their meanings during each interaction.&lt;/p&gt;
&lt;p&gt;The proposed governance rule is that &lt;strong&gt;every admitted organisational relationship type SHALL be defined in a versioned, approved template or semantic profile, with traceability to the applicable adopted standards or an explicitly approved organisational extension&lt;/strong&gt;. The profile records the standard edition and relevant requirement or definition where applicable. Where a standard leaves a modelling choice open, the organisation records its extension and rationale. This preserves standards-based discipline without asserting that industry standards already name every graph predicate used by an organisation. ISO/IEC/IEEE 42010:2022 and ISO/IEC/IEEE 29148:2018 inform the distinctions discussed earlier; the illustrative predicate names here are not standard-prescribed vocabulary.&lt;/p&gt;
&lt;p&gt;A relation definition needs more than a label. It identifies the permitted source and target concept types, direction, interpretation, applicable role and work product, and required qualifiers such as environment, time, polarity or evidence state. For example, &lt;code&gt;verifies&lt;/code&gt; might connect a verification activity to a requirement, while &lt;code&gt;producedEvidence&lt;/code&gt; connects its execution to a result. A planned test and a completed test cannot be substituted merely because both connect to the same requirement.&lt;/p&gt;
&lt;p&gt;Consider the sentence: “The Release Manager must approve production deployment after verification.” An association graph can connect the recognised concepts &lt;em&gt;Release Manager&lt;/em&gt;, &lt;em&gt;production deployment&lt;/em&gt; and &lt;em&gt;verification&lt;/em&gt;. In a governed release template, those associations could support the candidate propositions &lt;code&gt;deployment requiresApprovalFrom ReleaseManager&lt;/code&gt; and &lt;code&gt;deployment requiresEvidence verificationResult&lt;/code&gt;. These describe obligations; they do not record that approval was given or that verification passed. An observed approval requires separate evidence identifying its issuer, subject, decision and applicable version. The runtime must still establish that the issuer and acting agent have the necessary authority.&lt;/p&gt;
&lt;p&gt;Typing a connection is therefore a controlled interpretation step. A candidate keeps its source text and concept matches; the role template supplies permissible predicates and structural constraints; a check establishes whether the text and independent evidence support the proposed proposition. An extraction model can propose a type, but a plausible label is not sufficient to admit the claim as organisational knowledge. Ambiguous, unsupported or conflicting propositions remain unresolved. The association evidence is retained so that a reviewer can reconstruct how the candidate arose.&lt;/p&gt;
&lt;p&gt;Verification and validation must compare typed propositions and their qualifiers across the input, output and evaluation criteria, using approved mappings where views differ. A test that finds every concept but converts &lt;code&gt;requiresApprovalFrom&lt;/code&gt; into &lt;code&gt;approvedBy&lt;/code&gt;, or removes a prohibition, has changed the claim. The audit must expose that change. Graph coverage can find omitted concepts; checking typed relationships addresses whether the connections preserve the intended meaning.&lt;/p&gt;
&lt;h3 id=&quot;retrieving-an-approved-planning-template&quot;&gt;Retrieving an approved planning template&lt;/h3&gt;
&lt;p&gt;The following command is an illustrative invocation using the installed &lt;code&gt;terraphim-grep&lt;/code&gt; interface. The paths represent a proposed organisational knowledge layout; they are not supplied sample data or a claim that this particular corpus was executed.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;terraphim-grep&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;delivery plan&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --role&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Project Manager&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --haystack&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; all&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --paths&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; ./organisation/templates/planning&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --thesaurus&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; ./organisation/roles/project-manager/thesaurus.json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --search-only -n&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -C&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --json&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The dedicated thesaurus makes the role’s vocabulary concrete. &lt;code&gt;--search-only&lt;/code&gt; keeps this invocation on its search path without LLM synthesis. The implementation can fall back to thesaurus matching when populated graph evidence is absent; a result alone does not demonstrate graph traversal. Search produces candidates; the service then checks each candidate against the authoritative template registry. The chosen template must be approved, applicable to the project type, available to the active role and identified by an immutable revision or content digest. Restricting search paths narrows retrieval; it does not establish an execution sandbox.&lt;/p&gt;
&lt;p&gt;This distinction matters when a semantically excellent match is obsolete. The organisation’s semantic layer may help locate it, but the planning service must select an eligible template. If none exists, the service should request a governed template decision rather than manufacture an “approved” template itself.&lt;/p&gt;
&lt;h2 id=&quot;a-graph-based-planning-checklist&quot;&gt;A graph-based planning checklist&lt;/h2&gt;
&lt;p&gt;A checklist makes an expected output contract explicit. Terraphim’s published checklist approach places enumerated concepts outside the model and uses the same graph machinery for recognition and retrieval. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.terraphim.ai/src/howto/graph-embeddings-checklists&quot;&gt;Graph embeddings for checklists&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The current source also supports a paired input/output graph-coverage mode. An illustrative planning checklist, saved as &lt;code&gt;.terraphim/checklists/project_plan.md&lt;/code&gt;, is:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;markdown&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;font-weight: bold;&quot;&gt;# Project plan&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9AA5CE;&quot;&gt;mode:: graph-coverage-v1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9AA5CE;&quot;&gt;checklist:: scope, dependencies, risk register, acceptance criteria&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;font-weight: bold;&quot;&gt;### risk register&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9AA5CE;&quot;&gt;synonyms:: risk log&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Its concepts and aliases must resolve uniquely in the configured role graph; declaring an alias in a checklist does not create the missing graph concept. The checklist is not a substitute for building and governing that graph. A source-level invocation for the inspected implementation is:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;terraphim-agent&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; validate&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --role&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Project Manager&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --checklist&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; project_plan&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --input-file&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; brief.md&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;  --json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; plan.md&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This &lt;code&gt;--input-file&lt;/code&gt; form is supported by the inspected client source, not by the locally installed 1.21.22 command interface. The example is therefore a source-supported integration example, not an installed-binary demonstration.&lt;/p&gt;
&lt;p&gt;The paired check requires recognised input concepts and checklist concepts to appear in the output, with supporting stored graph paths. Its report distinguishes &lt;code&gt;pass&lt;/code&gt;, &lt;code&gt;fail&lt;/code&gt; and &lt;code&gt;indeterminate&lt;/code&gt;. A service using it as a gate must inspect that verdict; successful CLI completion alone does not establish a passing checklist.&lt;/p&gt;
&lt;p&gt;Concept coverage is one limited checking predicate. A plan can mention “dependencies” while assigning them incorrectly, or include “acceptance criteria” that do not test the promised outcome. The complete planning contract consequently layers structural checks, graph concept coverage and evidence review. The graph checker supplies an inspectable signal within that contract. It does not establish the full semantic compatibility contract, verify every asserted relationship or confer permission to publish or execute the plan. Its lexical negation handling does not constitute general verification of proposition meaning.&lt;/p&gt;
&lt;h2 id=&quot;worked-example-from-brief-to-bounded-plan&quot;&gt;Worked example from brief to bounded plan&lt;/h2&gt;
&lt;p&gt;Consider a project to deliver a customer-facing feature. The Product Manager agent receives an authorised assignment to prepare a feature breakdown. Its graph connects the product outcome to needs, features, value assumptions and acceptance criteria. It produces a versioned breakdown and hands that artefact to the Project Manager service.&lt;/p&gt;
&lt;p&gt;The Project Manager agent authenticates under its own scoped assignment. It retrieves candidate planning templates through its role thesaurus, selects an approved revision, and creates a draft connecting the agreed features to milestones, dependencies, owners and risks. It preserves the incoming acceptance criteria and identifies unresolved assumptions.&lt;/p&gt;
&lt;p&gt;The service checks the draft’s structure and invokes the graph checklist. A missing recognised requirement produces a failed or indeterminate result that must be resolved before the relevant transition. A passing result is recorded alongside its limitations. Further review establishes whether the proposed dependencies and acceptance evidence are adequate.&lt;/p&gt;
&lt;p&gt;When the service requests &lt;code&gt;create_draft&lt;/code&gt; on the assigned project’s document store, the gateway evaluates the exact operation, destination and content digest. Assuming the role assignment, template, checks and policy conditions are valid, it permits that write and records its outcome.&lt;/p&gt;
&lt;p&gt;Now suppose the agent requests &lt;code&gt;deploy&lt;/code&gt; against production. The request fails the role-to-service/action binding and the production policy. Mentioning deployment in the plan, retrieving a release runbook, or passing the planning checklist cannot repair that missing authority. The gateway records a denial before an effect occurs.&lt;/p&gt;
&lt;p&gt;The agent may instead hand the approved plan to the release management process. That handoff supplies evidence, not inherited production credentials. A separately authorised release principal must satisfy its own contract. The organisation can therefore automate preparation without collapsing preparation, approval and execution into a single unrestricted agent.&lt;/p&gt;
&lt;h3 id=&quot;checking-the-planning-context&quot;&gt;Checking the planning context&lt;/h3&gt;
&lt;p&gt;Consider an illustrative requirement &lt;strong&gt;R-17 revision 3&lt;/strong&gt;: the plan must specify a &lt;strong&gt;staging&lt;/strong&gt; rollback rehearsal whose planned start is no earlier than the simulated-failure trigger and no later than &lt;strong&gt;eight elapsed hours&lt;/strong&gt; afterwards. The baseline defines that trigger as the rehearsal protocol&#39;s injected-failure timestamp. Production deployment is outside the Project Manager&#39;s scope. The stakeholder need is to coordinate a usable rehearsal without delegating production execution.&lt;/p&gt;
&lt;p&gt;A verification criterion checks the plan&#39;s environment, planned start offset and preserved prohibition against that baseline. A validation scenario asks the delivery and release stakeholders whether the proposed handoff enables the intended rehearsal with the available people and resources. The plan&#39;s check does not prove that a rehearsal occurred. Later testing of the delivered system requires its own evidence; a good plan does not establish successful system behaviour.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Candidate interpretation or evidence&lt;/th&gt;&lt;th&gt;Required treatment under the proposed contract&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;“One business day” replaces eight elapsed hours&lt;/td&gt;&lt;td&gt;No silent equivalence. Resolve the calendar and conversion; fail if the interval changes, otherwise retain the approved mapping.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The plan schedules the rehearsal in production&lt;/td&gt;&lt;td&gt;Fail the known environment mismatch; separately deny unauthorised production actions.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;The evaluator uses revision 2&#39;s 24-hour threshold&lt;/td&gt;&lt;td&gt;Reject the stale criterion binding and reassess against revision 3.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;“Must not deploy” becomes “may deploy”&lt;/td&gt;&lt;td&gt;Fail proposition preservation despite matching deployment concepts.&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Relevant calendar or requirement revision is unknown&lt;/td&gt;&lt;td&gt;Return indeterminate until the baseline is resolved.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The same protection applies when views use different language. “Pre-production” can map to the named staging environment if the organisation explicitly defines that equivalence. Matching the spelling “staging” in an unrelated project&#39;s evidence cannot establish that the requirement was met.&lt;/p&gt;
&lt;h2 id=&quot;terraph-audit-with-one-role-and-one-checklist&quot;&gt;Terraph audit with one role and one checklist&lt;/h2&gt;
&lt;p&gt;This Terraph example connects a role graph, a checklist and three verbs: &lt;code&gt;audit&lt;/code&gt;, &lt;code&gt;check&lt;/code&gt; and &lt;code&gt;deploy&lt;/code&gt;. Here, &lt;code&gt;engineer&lt;/code&gt; is the example role; it does not change the Project Manager’s authority. The graph and checklist are Markdown inputs compiled into constant matching automata. &lt;code&gt;embed&lt;/code&gt; and &lt;code&gt;satisfies&lt;/code&gt; are language intrinsics, so retrieval and checking use the same concept definitions.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;import std;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;role engineer from &amp;quot;kg&amp;quot;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;checklist preflight from &amp;quot;checklists/preflight.md&amp;quot;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;// Audit concept coverage and report the matching source spans.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fn audit(path: str) -&amp;gt; i64 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    let src = read_file(path);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if src.len == 0 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;cannot read &amp;quot;, path);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        return 1;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    let h = embed(src);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    let cov = coverage(h);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;file: &amp;quot;, path);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;kg_hits: &amp;quot;, cov.kg_hits, &amp;quot;  concepts: &amp;quot;, cov.concepts,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          &amp;quot;  confidence: &amp;quot;, cov.confidence, &amp;quot;  diversity: &amp;quot;, cov.diversity);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    for m in h {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;  &amp;quot;, m.concept, &amp;quot; @&amp;quot;, m.start, &amp;quot;..&amp;quot;, m.end);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if cov.sufficient() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;sufficient: yes&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        return 0;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;sufficient: no&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return 1;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;// Diagnose missing checklist items. This verb does not issue a proof.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fn check(text: str) -&amp;gt; i64 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    let miss = text satisfies preflight;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    if miss.any() {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        print(&amp;quot;checklist preflight: incomplete&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        miss.report();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        return 4;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;checklist preflight: complete&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return 0;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;// The generated wrapper supplies a sealed proof for the checked snapshot.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fn deploy(plan: str, ev: Proof&amp;lt;preflight&amp;gt;) -&amp;gt; i64 {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print(&amp;quot;deploy: preflight evidence present, proceeding&amp;quot;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    return 0;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;audit&lt;/code&gt; exposes which concepts matched and where. &lt;code&gt;check&lt;/code&gt; reports missing checklist items. At the gated entry point, the generated verb wrapper obtains a sealed &lt;code&gt;Proof&amp;lt;preflight&amp;gt;&lt;/code&gt; through &lt;code&gt;.require()&lt;/code&gt;, which succeeds only when no items are missing. The function signature makes that evidence a prerequisite for entering &lt;code&gt;deploy&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The proof carries the checked snapshot as &lt;code&gt;ev.subject&lt;/code&gt;. Any operation justified by the gate must consume that snapshot; reopening the path in &lt;code&gt;plan&lt;/code&gt; could read changed, unchecked bytes. The sample body only prints a message. Actual deployment still requires an authorised role assignment and resource policy, and concept coverage alone does not establish that the plan is correct. The example shows the language boundary; it is not a recorded deployment.&lt;/p&gt;
&lt;h2 id=&quot;adf-configuration-gives-the-role-an-organisational-task&quot;&gt;ADF configuration gives the role an organisational task&lt;/h2&gt;
&lt;p&gt;The ADF agent orchestration configurations assign organisational responsibilities. The checked-in Product Owner template names an implementation and declares these fields. Product Owner is the configured role; it is distinct from the illustrative Product Manager role used earlier:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;agents&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;product-owner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;persona&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Themis&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;capabilities&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt; [&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;planning&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;roadmap&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;issue-creation&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;prioritisation&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;project&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;terraphim&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Its skill chain includes research, design, specification, architecture, business scenario design, requirements traceability and acceptance testing. The task defines the work product: each proposed issue must identify its organisational goal, describe the problem and proposed solution, and supply Given–When–Then acceptance criteria. The template also requires a priority estimate, a communication hint and the suggested delivery agent. The workflow narrows the backlog, scores the surviving items and proposes up to two new issues.&lt;/p&gt;
&lt;p&gt;These selected literal fields show the existing issue template. Its brackets indicate fields the Product Owner must fill; WIG means the organisation’s current Wildly Important Goal.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Title: [concise, imperative]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;WIG: [which WIG this serves, or skip if none]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Problem: [2-3 sentences describing the problem]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Proposed solution: [bullet points, no hand-waving]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Acceptance criteria (mini-UAT):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Given [precondition]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  When [action]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  Then [observable outcome]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The configuration connects the Product Owner’s planning capability to a defined work product and template. It records operational intent; this inspection does not establish that the agent is deployed or that every configured step succeeds.&lt;/p&gt;
&lt;p&gt;The repo-local ADF configuration separately declares a Developer, Reviewer and Merge Coordinator, with distinct capability lists and named Terraphim roles:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Configured agent&lt;/th&gt;&lt;th&gt;Declared Terraphim role&lt;/th&gt;&lt;th&gt;Responsibility expressed in the configuration&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;developer&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Terraphim AI Developer&lt;/td&gt;&lt;td&gt;Implementation, Rust development and test-driven development&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;reviewer&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Terraphim AI Reviewer&lt;/td&gt;&lt;td&gt;Code review, quality gates and review coordination&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&lt;code&gt;merge-coordinator&lt;/code&gt;&lt;/td&gt;&lt;td&gt;Terraphim AI Merge Coordinator&lt;/td&gt;&lt;td&gt;Merge coordination, CI/CD and conflict resolution&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;The orchestrator’s merge path checks four required status contexts: &lt;code&gt;native-ci / build (push)&lt;/code&gt;, &lt;code&gt;adf/pr-reviewer&lt;/code&gt;, &lt;code&gt;adf/validation&lt;/code&gt; and &lt;code&gt;adf/verification&lt;/code&gt;. It also requires canonical gate-result records for the current pull request head. Blocking findings and the project&#39;s treatment of concerns affect the decision. Evidence for an older commit cannot substitute for the current head’s review, binding the decision to that part of its context baseline. The labels &lt;code&gt;adf/validation&lt;/code&gt; and &lt;code&gt;adf/verification&lt;/code&gt; do not establish that their producers perform the corresponding ISO requirements or system activities.&lt;/p&gt;
&lt;p&gt;Configuration intent and runtime enforcement must remain distinguishable. The inspected repo-local loader sets &lt;code&gt;terraphim_role&lt;/code&gt; to &lt;code&gt;None&lt;/code&gt;; the declaration alone does not prove that an agent receives the named role graph. Instructions such as “do not merge” are task text, and the Product Owner’s broad shell access is not a production-deployment barrier. The merge gate controls the orchestrator’s merge path; it does not prove that every alternative credential or tool path is mediated. Its structured records are not independently authenticated merely by having the expected fields.&lt;/p&gt;
&lt;p&gt;ADF declares responsibility, capabilities, workflow and expected artefacts. Terraph implements bounded tool access, checks and receipts; Terraphim provides the role vocabulary and graph context. Connecting them still requires authenticated role assignments, capability-to-service identifiers, approved artefact versions and policy decisions tied to exact requests.&lt;/p&gt;
&lt;p&gt;W3C PROV provides terms for recording entities, activities and agents, including derivation, association and delegated responsibility. These relationships can describe an artefact’s origin and an agent’s participation; a provenance statement alone is not an authorisation decision. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.w3.org/TR/prov-o/&quot;&gt;W3C PROV-O&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;evaluation-and-implementation-boundaries&quot;&gt;Evaluation and implementation boundaries&lt;/h2&gt;
&lt;p&gt;The proposal can be evaluated without assuming that more graph coverage means safer behaviour. A test corpus should pair legitimate planning tasks with boundary cases and preserve the same role assignments and policy across agent implementations.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Test&lt;/th&gt;&lt;th&gt;Expected observable result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Valid plan from an approved template&lt;/td&gt;&lt;td&gt;Draft created in the assigned project with complete evidence links&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Semantically relevant but withdrawn template&lt;/td&gt;&lt;td&gt;Candidate rejected by template eligibility policy&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Required concept omitted&lt;/td&gt;&lt;td&gt;Graph report identifies a fail or indeterminate result; gated transition does not proceed&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;All terms present but a dependency is wrong&lt;/td&gt;&lt;td&gt;Concept coverage may pass; substantive review detects the error&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Project Manager requests production deployment&lt;/td&gt;&lt;td&gt;Denied before any deployment effect&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Deployment attempted through an alternative tool&lt;/td&gt;&lt;td&gt;Same authority boundary enforced&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Artefact changes after checking&lt;/td&gt;&lt;td&gt;Previous evidence rejected for the changed request or bytes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Role assignment expires before execution&lt;/td&gt;&lt;td&gt;Gateway denies or requires a fresh valid assignment&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Agent implementation is replaced&lt;/td&gt;&lt;td&gt;Service contract and authority boundaries remain unchanged&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Concepts match but polarity, environment or units differ&lt;/td&gt;&lt;td&gt;Relevant semantic predicate fails, or unresolved meaning is indeterminate&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;A role projection drops a critical obligation&lt;/td&gt;&lt;td&gt;Trace check rejects the transformation or requires an approved change&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Different role views have an approved meaning-preserving mapping&lt;/td&gt;&lt;td&gt;Compatibility can be established; substantive criteria still require evidence&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Measurements should include accepted legitimate tasks, incorrect denials, unauthorised effects, trace completeness and the cost of reconstructing a decision. Report semantic-check accuracy separately from policy enforcement. A test that finds no bypass in a bounded suite is evidence about that suite, not proof that all possible tool paths are mediated.&lt;/p&gt;
&lt;p&gt;Terraphim already supplies relevant semantic components, and Terraph supplies concrete prototype mechanisms for compiled checks and evidence. ADF provides configured organisational responsibilities and an implemented orchestrator merge gate. The end-to-end organisational contract, contextual requirement-to-criterion alignment, authenticated role binding, complete execution mediation and linked audit schema remain the integration proposed in this paper. No production deployment result or benchmark is claimed here.&lt;/p&gt;
&lt;p&gt;Role owners must maintain concepts, templates and policies, and reviewers must understand what each checklist establishes. Graph updates need controlled promotion because a vocabulary change can alter which obligations appear satisfied. Audit records should retain enough versioned evidence to reconstruct decisions while limiting sensitive content.&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;An agent’s organisational role provides a durable basis for knowledge, responsibility and delegated authority. Capabilities explain the outcomes the role must support; services describe how an agent implementation supplies them; tools expose actions; contextual policy determines which actions may occur. A role-based knowledge graph makes the concepts and relationships behind the work inspectable. Meaningful verification and validation also require those concepts, their propositions and the operating context to align with the applicable criteria through explicit, traceable mappings. A shared vocabulary alone cannot preserve an obligation.&lt;/p&gt;
&lt;p&gt;Terraphim supplies explicit concept matching, co-occurrence associations, graph retrieval and graph-based checklists. The proposed next layer types those associations using governed role templates and standards-traceable relationship definitions, distinguishing a mention from an obligation and an obligation from an evidenced event. Terraph illustrates how compiled checks can produce evidence tied to the subject being checked. Connecting these mechanisms to authenticated role assignments and mediated execution yields a traceable organisational contract.&lt;/p&gt;
&lt;p&gt;For a Project Manager agent, the contract requires an approved planning template, preserved requirements, a checked plan and operation within the assigned project scope. Production deployment belongs to a separately authorised role and process. The evidence must allow a reviewer to reconstruct both the planning result and the authority decision.&lt;/p&gt;
&lt;h2 id=&quot;sources-and-scope&quot;&gt;Sources and scope&lt;/h2&gt;
&lt;p&gt;Public sources are linked beside the claims they support. The preceding article by David Hunt and Alexander Mikhalev was published on 31 October 2026 and read on 4 November. The continuation and concept mapping are this paper&#39;s synthesis.&lt;/p&gt;
&lt;p&gt;Terraphim and ADF implementation details were checked against local source on 3–4 November 2026. The Terraph example above was supplied by Alexander Mikhalev; its comments have been shortened and its function bodies retained. Source revisions, implementation paths, recorded fixture results and inspection limits remain in the internal research notes.&lt;/p&gt;
&lt;p&gt;The standards cross-check used official catalogue records and accessible previews. The complete normative text of ISO/IEC/IEEE 42010:2022 was not inspected, so no clause-by-clause conformity claim is made. The role contracts, typed relationship profiles, contextual criteria and cross-system bindings are proposed integration work. The examples do not demonstrate a live production deployment.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Support the project</title>
          <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/donate/</link>
          <guid>https://reference-architecture.ai/docs/donate/</guid>
          <description xml:base="https://reference-architecture.ai/docs/donate/">&lt;p&gt;The patterns described on this site are not theory. They are extracted from
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.ai&quot;&gt;Terraphim&lt;/a&gt;, a privacy-first AI assistant built across 52 Rust
crates, and every one of those crates is open source.&lt;/p&gt;
&lt;p&gt;The most valuable support is use and scrutiny.&lt;/p&gt;
&lt;h2 id=&quot;use-it&quot;&gt;Use it&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.ai&quot;&gt;terraphim.ai&lt;/a&gt;&lt;/strong&gt; — the assistant itself: local-first, your data
stays on your device.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.rs&quot;&gt;terraphim.rs&lt;/a&gt;&lt;/strong&gt; — the engine: 52 crates, each with a single
responsibility and usable independently. Start with
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_automata&quot;&gt;&lt;code&gt;terraphim_automata&lt;/code&gt;&lt;/a&gt; for Aho-Corasick matching,
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_rolegraph&quot;&gt;&lt;code&gt;terraphim_rolegraph&lt;/code&gt;&lt;/a&gt; for role-based knowledge
graphs, or &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_persistence&quot;&gt;&lt;code&gt;terraphim_persistence&lt;/code&gt;&lt;/a&gt; for the
storage layer.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;contribute&quot;&gt;Contribute&lt;/h2&gt;
&lt;p&gt;Issues, benchmarks and architecture critique are worth more than money here. If a
trade-off on this site looks wrong, say so — with evidence — at
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/terraphim&quot;&gt;github.com/terraphim&lt;/a&gt;. Deployment guides and reproducible
benchmarks are especially welcome.&lt;/p&gt;
&lt;h2 id=&quot;sponsor&quot;&gt;Sponsor&lt;/h2&gt;
&lt;p&gt;If your organisation depends on this work, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.pro&quot;&gt;Terraphim Pro&lt;/a&gt; funds
the open-source engine directly: connectors, an LLM proxy and agentic skills for
enterprise deployment.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>The Twelve Core Patterns</title>
          <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/patterns/</link>
          <guid>https://reference-architecture.ai/docs/patterns/</guid>
          <description xml:base="https://reference-architecture.ai/docs/patterns/">&lt;p&gt;The harness, not the model, determines agent success. A harness has three jobs — deciding
what the model sees, enforcing what it can do, and ensuring it learns from its own history
— and each job is served by four patterns.&lt;/p&gt;
&lt;p&gt;Every pattern below is documented elsewhere on this site. This page is the index, not the
explanation: each entry links to where the argument is actually made.&lt;/p&gt;
&lt;h2 id=&quot;context-architecture&quot;&gt;Context Architecture&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;What the model sees at each step.&lt;/em&gt; Context is a scarce resource: a 1M token window with
800K of noise performs worse than 200K with 150K of curated signal.&lt;/p&gt;
&lt;h3 id=&quot;1-structural-context-boundary&quot;&gt;1. Structural Context Boundary&lt;/h3&gt;
&lt;p&gt;Put the boundary in configuration, not in a runtime permission check. A role has access
to certain sources; the knowledge graph is built from those sources; the agent therefore
cannot reach anything outside its role. Not a check that could be bypassed — an absence.
The data was never loaded.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/terraphim-engine-architecture/#layer-1-types-and-configuration&quot;&gt;The Terraphim Engine, Layer 1&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;2-deterministic-concept-matching&quot;&gt;2. Deterministic Concept Matching&lt;/h3&gt;
&lt;p&gt;Resolve text to concepts with finite state automata rather than vector similarity.
Aho-Corasick finds every match in O(n) time, with the same result every run. Probabilistic
retrieval gives you a different context window each time you ask, which makes every
downstream failure irreproducible.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/mcp-native-agent-architecture/#layer-2-knowledge-graph&quot;&gt;The MCP-Native Agent Architecture, Layer 2&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;3-structured-compaction&quot;&gt;3. Structured Compaction&lt;/h3&gt;
&lt;p&gt;Compact before the window fills, not when it overflows. By 100K tokens a working context
is largely noise: superseded search results, abandoned reasoning paths, old file reads.
Adding capacity without compaction makes performance worse, not better.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;/#failures&quot;&gt;Three ways 1M token windows fail&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;4-priority-weighted-instruction-injection&quot;&gt;4. Priority-Weighted Instruction Injection&lt;/h3&gt;
&lt;p&gt;Instructions compete, and by default the loudest wins rather than the most important. The
system prompt says one thing, the project file another, the README a third. Weight them
explicitly and re-inject the high-priority ones, rather than trusting position in a
transcript.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;/#failures&quot;&gt;Three ways 1M token windows fail&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;execution-guardrails&quot;&gt;Execution Guardrails&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;What the model can and cannot do.&lt;/em&gt; Risk-tiered, machine-readable, and enforced by the
system rather than requested in a prompt.&lt;/p&gt;
&lt;h3 id=&quot;5-multi-tenant-agent-isolation&quot;&gt;5. Multi-Tenant Agent Isolation&lt;/h3&gt;
&lt;p&gt;Agents sharing a protocol layer must not share state. Each agent keeps its own role
configuration and its own knowledge graph, discovering the others&#39; tools without
discovering their data.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/mcp-native-agent-architecture/#pattern-1-multi-tenant-agent-isolation&quot;&gt;Pattern 1: Multi-Tenant Agent Isolation&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;6-deterministic-replay&quot;&gt;6. Deterministic Replay&lt;/h3&gt;
&lt;p&gt;An agent run you cannot replay is an agent run you cannot debug. Record the inputs and the
decisions such that the same run can be reconstructed exactly — which is only possible if
the layers underneath are themselves deterministic.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/mcp-native-agent-architecture/#pattern-2-deterministic-replay&quot;&gt;Pattern 2: Deterministic Replay&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;7-human-in-the-loop-for-destructive-operations&quot;&gt;7. Human-in-the-Loop for Destructive Operations&lt;/h3&gt;
&lt;p&gt;Classify tools by effect, not by name. Read-only operations run freely; destructive ones
stop for approval. The protocol enforces the distinction, so an agent cannot talk its way
past it.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/mcp-native-agent-architecture/#pattern-3-human-in-the-loop-for-destructive-operations&quot;&gt;Pattern 3: Human-in-the-Loop for Destructive Operations&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;8-break-glass&quot;&gt;8. Break-Glass&lt;/h3&gt;
&lt;p&gt;Every guardrail needs a deliberate, logged way through it. A guardrail with no override
gets disabled wholesale the first time it blocks something urgent; an override that is
not recorded is indistinguishable from the guardrail not existing.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/harness-engineering-agents/#harness-3-break-glass&quot;&gt;Harness 3: Break-Glass&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;memory-infrastructure&quot;&gt;Memory Infrastructure&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Ensuring the model learns from its own history.&lt;/em&gt; Without it, agents repeat solved
problems indefinitely and no amount of context helps.&lt;/p&gt;
&lt;h3 id=&quot;9-novelty-filter&quot;&gt;9. Novelty Filter&lt;/h3&gt;
&lt;p&gt;Distinguish output that is new from output that merely looks new. An agent that cannot
tell repetition from progress will re-report the same finding until someone stops reading.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/harness-engineering-agents/#harness-1-novelty-filter&quot;&gt;Harness 1: Novelty Filter&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;10-calculated-health&quot;&gt;10. Calculated Health&lt;/h3&gt;
&lt;p&gt;Derive a health signal from observable metrics rather than asking the agent how it is
doing. Self-assessment is the least reliable input available; commit recency, unapplied
lessons and stall time are not.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/harness-engineering-agents/#harness-2-calculated-health&quot;&gt;Harness 2: Calculated Health&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;11-lesson-window&quot;&gt;11. Lesson Window&lt;/h3&gt;
&lt;p&gt;Capture corrections at the moment of failure and apply them within a bounded window.
Lessons with no expiry become noise; lessons never applied were never lessons.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;https://reference-architecture.ai/posts/harness-engineering-agents/#harness-4-lesson-window&quot;&gt;Harness 4: Lesson Window&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&quot;12-drift-detection&quot;&gt;12. Drift Detection&lt;/h3&gt;
&lt;p&gt;Long-running agents optimise for local coherence and lose the original objective. Ask
periodically, and mechanically: do we actually have the thing we set out to build? The
question has to be asked by the harness, because an agent that has drifted cannot detect
its own drift.&lt;/p&gt;
&lt;p&gt;→ &lt;a href=&quot;/#failures&quot;&gt;Three ways 1M token windows fail&lt;/a&gt; ·
&lt;a href=&quot;/#flywheel&quot;&gt;The nine-step orchestration arc&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&quot;on-this-list&quot;&gt;On this list&lt;/h2&gt;
&lt;p&gt;These twelve are the patterns this site currently makes an argument for, grouped by
&lt;a href=&quot;/#harness&quot;&gt;the three jobs of an agent harness&lt;/a&gt;. The grouping is deliberate: a pattern
that does not serve one of those three jobs probably belongs in a different architecture.&lt;/p&gt;
&lt;p&gt;The list is not a claim to completeness. It is what is documented, and the honest test of
any addition is whether there is an article behind it.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>The Terraphim Engine: Six Layers, Fifty-Two Crates</title>
          <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/terraphim-engine-architecture/</link>
          <guid>https://reference-architecture.ai/posts/terraphim-engine-architecture/</guid>
          <description xml:base="https://reference-architecture.ai/posts/terraphim-engine-architecture/">&lt;p&gt;The diagram on the front page of this site is not an illustration. Every box in it is a
published Rust crate you can &lt;code&gt;cargo add&lt;/code&gt; today, read the documentation for, and use
without taking the rest of the system. This article explains what sits behind each box,
and why the decomposition is the interesting part.&lt;/p&gt;
&lt;p&gt;&lt;span id=&quot;continue-reading&quot;&gt;&lt;/span&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-decomposition-is-the-architecture&quot;&gt;Why decomposition is the architecture&lt;/h2&gt;
&lt;p&gt;Most agent frameworks ship as a single dependency. You take the orchestrator, the memory
layer, the retrieval stack and the tool protocol together, or you take none of it. That
is convenient at first and expensive later: when one layer misbehaves you cannot isolate
it, and when you want to replace one you replace all of them.&lt;/p&gt;
&lt;p&gt;The pattern this site argues for is the opposite. Draw the boundaries first, make each
one independently useful, and let the seams stay visible. Terraphim is built that way —
52 crates across six layers, each with a single responsibility — which makes it a
reasonable worked example rather than a product pitch.&lt;/p&gt;
&lt;p&gt;The test of a boundary is whether you can use one side without the other. Here you can:
&lt;code&gt;terraphim_automata&lt;/code&gt; is a text-matching engine that happens to be used by a knowledge
graph; &lt;code&gt;terraphim_persistence&lt;/code&gt; is a storage abstraction that does not know what it is
storing.&lt;/p&gt;
&lt;h2 id=&quot;the-six-layers&quot;&gt;The six layers&lt;/h2&gt;
&lt;p&gt;Terraphim organises its crates into a dependency graph with six levels. Lower layers do
not know the higher ones exist.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Layer&lt;/th&gt;&lt;th&gt;Concern&lt;/th&gt;&lt;th&gt;Representative crates&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;User interfaces&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_agent&quot;&gt;&lt;code&gt;terraphim_agent&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim-cli&quot;&gt;&lt;code&gt;terraphim-cli&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_server&quot;&gt;&lt;code&gt;terraphim_server&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;Orchestration&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_orchestrator&quot;&gt;&lt;code&gt;terraphim_orchestrator&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_kg_orchestration&quot;&gt;&lt;code&gt;terraphim_kg_orchestration&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;terraphim_symphony&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;Agent system&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_spawner&quot;&gt;&lt;code&gt;terraphim_spawner&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_router&quot;&gt;&lt;code&gt;terraphim_router&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_agent_supervisor&quot;&gt;&lt;code&gt;terraphim_agent_supervisor&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;Service layer&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_service&quot;&gt;&lt;code&gt;terraphim_service&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_middleware&quot;&gt;&lt;code&gt;terraphim_middleware&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;haystack_*&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;Core engine&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_automata&quot;&gt;&lt;code&gt;terraphim_automata&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_rolegraph&quot;&gt;&lt;code&gt;terraphim_rolegraph&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_persistence&quot;&gt;&lt;code&gt;terraphim_persistence&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;Types and configuration&lt;/td&gt;&lt;td&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_types&quot;&gt;&lt;code&gt;terraphim_types&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_config&quot;&gt;&lt;code&gt;terraphim_config&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_settings&quot;&gt;&lt;code&gt;terraphim_settings&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;That ordering matters more than the crate count. An agent system that cannot say which
layer a failure came from is a system you cannot debug in production.&lt;/p&gt;
&lt;h2 id=&quot;layer-1-types-and-configuration&quot;&gt;Layer 1: types and configuration&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;terraphim_types&lt;/code&gt; is the shared vocabulary — the structures every other crate agrees on.
&lt;code&gt;terraphim_config&lt;/code&gt; holds role definitions, haystacks and LLM routing;
&lt;code&gt;terraphim_settings&lt;/code&gt; handles runtime preferences.&lt;/p&gt;
&lt;p&gt;Putting roles in configuration rather than code is what makes the context boundary
structural. A role has access to certain haystacks; the knowledge graph is built from
those haystacks; therefore the agent cannot reach information outside its role. That is
not a permission check at runtime that could be bypassed — it is an absence. The data
was never loaded.&lt;/p&gt;
&lt;h2 id=&quot;layer-2-the-core-engine&quot;&gt;Layer 2: the core engine&lt;/h2&gt;
&lt;p&gt;This is the layer the front-page diagram mostly depicts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_automata&quot;&gt;&lt;code&gt;terraphim_automata&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; is the matching engine:
Aho-Corasick finite state automata that match thousands of patterns simultaneously in
O(n) time, where n is the length of the text. Not &quot;usually fast&quot; — bounded, and the same
bound every time. It compiles to WebAssembly, which is why the same matcher runs in a
browser as on a server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_rolegraph&quot;&gt;&lt;code&gt;terraphim_rolegraph&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; is the knowledge graph.
It is deliberately not a general-purpose graph database. It maps search roles to
domain-specific graph views, and it exists to do one thing quickly: turn text into
concepts, deterministically. Terraphim reports knowledge-graph inference in the 5-10
nanosecond range and a 15 MB memory footprint, with no GPU — figures worth checking
against your own workload, but the shape of the claim follows from the design rather
than from optimisation tricks.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_persistence&quot;&gt;&lt;code&gt;terraphim_persistence&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; provides the
&lt;code&gt;Persistable&lt;/code&gt; trait and DeviceStorage backends across memory, SQLite and redb. Storage is
an interface here, not an assumption, which is what lets the same engine run on a laptop
and at the edge.&lt;/p&gt;
&lt;h2 id=&quot;layer-3-the-service-layer&quot;&gt;Layer 3: the service layer&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_middleware&quot;&gt;&lt;code&gt;terraphim_middleware&lt;/code&gt;&lt;/a&gt; searches &lt;em&gt;haystacks&lt;/em&gt; —
pluggable data-source backends. This is the boundary the front-page diagram labels
Document Input. A haystack might be a local folder, a repository, or a connector to
something else; the layers above do not change when you add one.&lt;/p&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_service&quot;&gt;&lt;code&gt;terraphim_service&lt;/code&gt;&lt;/a&gt; handles requests and responses
for the core, which keeps request handling out of the engine itself.&lt;/p&gt;
&lt;h2 id=&quot;layers-4-and-5-agents-and-orchestration&quot;&gt;Layers 4 and 5: agents and orchestration&lt;/h2&gt;
&lt;p&gt;Above the service layer sit the agent system (&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_spawner&quot;&gt;&lt;code&gt;terraphim_spawner&lt;/code&gt;&lt;/a&gt;, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_router&quot;&gt;&lt;code&gt;terraphim_router&lt;/code&gt;&lt;/a&gt;,
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_agent_supervisor&quot;&gt;&lt;code&gt;terraphim_agent_supervisor&lt;/code&gt;&lt;/a&gt;) and orchestration (&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_orchestrator&quot;&gt;&lt;code&gt;terraphim_orchestrator&lt;/code&gt;&lt;/a&gt;,
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_kg_orchestration&quot;&gt;&lt;code&gt;terraphim_kg_orchestration&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;terraphim_symphony&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The distinction is worth holding onto. The agent system is concerned with individual
agents — spawning them, routing to them, supervising them. Orchestration is concerned
with what happens between them. Collapsing those two into one &quot;agent framework&quot; is the
usual mistake, and it is why so many systems cannot tell a stuck agent from a stuck
workflow.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://reference-architecture.ai/posts/mcp-native-agent-architecture/&quot;&gt;The MCP-Native Agent Architecture&lt;/a&gt; goes
into the protocol surface these layers expose, and why treating MCP as an architectural
primitive rather than a transport changes what the system can guarantee.&lt;/p&gt;
&lt;h2 id=&quot;layer-6-the-interfaces&quot;&gt;Layer 6: the interfaces&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_agent&quot;&gt;&lt;code&gt;terraphim_agent&lt;/code&gt;&lt;/a&gt; is the interactive REPL with session
search and learning capture. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim-cli&quot;&gt;&lt;code&gt;terraphim-cli&lt;/code&gt;&lt;/a&gt; is the
automation-shaped counterpart, with JSON output for scripting.
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_server&quot;&gt;&lt;code&gt;terraphim_server&lt;/code&gt;&lt;/a&gt; provides the REST API.&lt;/p&gt;
&lt;p&gt;Three interfaces over one engine, none of them privileged. That is the payoff of the
layering: the CLI is not a thin wrapper around the server, and the server is not a
special case. They are peers over the same core.&lt;/p&gt;
&lt;h2 id=&quot;what-to-take-from-this&quot;&gt;What to take from this&lt;/h2&gt;
&lt;p&gt;You do not need to adopt Terraphim to use the pattern. The transferable parts are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Draw layers that a failure can be attributed to.&lt;/strong&gt; If you cannot name the layer, you
cannot fix the bug.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Make each boundary independently useful.&lt;/strong&gt; A crate nobody would use on its own is
usually not a boundary, it is a split file.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Put the context boundary in configuration, not in runtime checks.&lt;/strong&gt; Structural
impossibility beats a permission test.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep the expensive guarantees low.&lt;/strong&gt; Determinism in the matching engine is worth more
than determinism bolted onto the orchestrator.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;documentation&quot;&gt;Documentation&lt;/h2&gt;
&lt;p&gt;Every crate named above is published and documented:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.rs&quot;&gt;terraphim.rs&lt;/a&gt;&lt;/strong&gt; — the engine: all 52 crates, grouped by layer,
with the dependency graph and installation instructions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_automata&quot;&gt;docs.rs&lt;/a&gt;&lt;/strong&gt; — per-crate API documentation,
generated from source. Start with
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_automata&quot;&gt;&lt;code&gt;terraphim_automata&lt;/code&gt;&lt;/a&gt; for matching,
&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_rolegraph&quot;&gt;&lt;code&gt;terraphim_rolegraph&lt;/code&gt;&lt;/a&gt; for the knowledge graph,
or &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.rs/terraphim_persistence&quot;&gt;&lt;code&gt;terraphim_persistence&lt;/code&gt;&lt;/a&gt; for storage.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.terraphim.ai&quot;&gt;docs.terraphim.ai&lt;/a&gt;&lt;/strong&gt; — the full documentation site:
guides, deployment and integration patterns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://terraphim.ai&quot;&gt;terraphim.ai&lt;/a&gt;&lt;/strong&gt; — the assistant built on all of it, if you
would rather see the system working before reading its parts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Installation is a single command, or &lt;code&gt;cargo install terraphim_agent&lt;/code&gt; if you would prefer
to start from the REPL.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>The MCP-Native Agent Architecture</title>
          <pubDate>Mon, 07 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/mcp-native-agent-architecture/</link>
          <guid>https://reference-architecture.ai/posts/mcp-native-agent-architecture/</guid>
          <description xml:base="https://reference-architecture.ai/posts/mcp-native-agent-architecture/">&lt;p&gt;A reference architecture for production AI systems, drawn from five years building Terraphim — a privacy-first AI assistant with ~50 Rust crates, MCP-native interfaces, and role-based multi-agent orchestration.&lt;/p&gt;</description>
      </item>
      <item>
          <title>Harness Engineering for Self-Improving Agents</title>
          <pubDate>Sun, 06 Sep 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/harness-engineering-agents/</link>
          <guid>https://reference-architecture.ai/posts/harness-engineering-agents/</guid>
          <description xml:base="https://reference-architecture.ai/posts/harness-engineering-agents/">&lt;p&gt;Many AI agent systems plateau after deployment. They execute tasks, but the surrounding system may not measure whether they are getting better, repeating old work, or normalizing stalled execution. This article proposes a reference pattern for &lt;strong&gt;agent harnesses&lt;/strong&gt;: supervised feedback loops that make agent behavior observable, measurable, and easier to improve.&lt;/p&gt;</description>
      </item>
      <item>
          <title>Turning Open Source project into Product with Redis Enterprise</title>
          <pubDate>Fri, 19 Aug 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/github-oauth2/</link>
          <guid>https://reference-architecture.ai/posts/github-oauth2/</guid>
          <description xml:base="https://reference-architecture.ai/posts/github-oauth2/">&lt;h1 id=&quot;turning-open-source-project-into-product-with-redis-enterprise&quot;&gt;Turning Open Source project into Product with Redis Enterprise&lt;/h1&gt;
&lt;h1 id=&quot;overview&quot;&gt;Overview&lt;/h1&gt;
&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;
&lt;h2 id=&quot;history&quot;&gt;History&lt;/h2&gt;
&lt;p&gt;Last year, my reference project, &quot;The Pattern&quot;, was the hackathon winner 2021 and got a bit of publicity and, in total, seven forks. But as with many open source projects, it is now stale. Time to revive &quot;The Pattern&quot; with new features and GitHub sponsors or Patreon patrons to help and inspire developers and creatives. In return, it&#39;s common to provide sponsor-only features and articles. Nevertheless, how can we do it with a large Redis-based machine learning pipeline?&lt;/p&gt;
&lt;h2 id=&quot;plan-sponsor-only-features&quot;&gt;Plan sponsor only features&lt;/h2&gt;
&lt;p&gt;This article will introduce a simple first step:
for GitHub sponsors, we start with offering persistent storage of preferences: I have a simple flask POST API which adds nodes into the user&#39;s preference storage - a simple Redis set per user. And it will be a foundation to build other sponsor-only features.
For now, let&#39;s cover the basics:&lt;/p&gt;
&lt;h1 id=&quot;overall-architecture-overview&quot;&gt;Overall architecture overview&lt;/h1&gt;
&lt;div class=&quot;mermaid-wrap&quot;&gt;&lt;pre class=&quot;mermaid&quot;&gt;
flowchart LR
    id1(User) --&gt; flask_login(Flask Login API)--&gt; github(GitHub OAuth2)
    github--&gt;flask_callback(Flask API callback)--&gt;GitHubGraphQL(GitHub GraphQL)
&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id=&quot;add-github-oauth2-to-rest-api&quot;&gt;Add Github oauth2 to Rest API&lt;/h2&gt;
&lt;p&gt;There are a number of API&#39;s that GitHub offers to help developers, but the GitHub Authentication API is one of the most popular. This API allows you to log in to GitHub using your username and password, or OAuth token.&lt;/p&gt;
&lt;p&gt;A login button with a standard OIDC/OAuth2 dance is one of the most common ways for a user to authenticate to an API.
Below is code taken from this &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://gist.github.com/xros/aba970d1098d916200d0acce8feb0251&quot;&gt;gist&lt;/a&gt; and is very common for OAuth2 flows:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;import&lt;/span&gt;&lt;span&gt; os &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;client_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;GITHUB_CLIENT_ID&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;client_secret&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;GITHUB_SECRET&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;app&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;route&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; methods&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;POST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;]&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; index&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;https://github.com/login/oauth/authorize&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    params&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;client_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span&gt; client_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;read:user,read:email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;uuid4&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hex&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;allow_signup&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; furl&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; redirect&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 302&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where GITHUB_CLIENT_ID and GITHUB_SECRET are client/secret GitHub Oauth2 apps. Register for following process on &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/settings/applications/new&quot;&gt;GitHub&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;On callback:
&lt;ul&gt;
&lt;li&gt;Fetch username, email, and other profile information- in case we need to contact them&lt;/li&gt;
&lt;li&gt;get the status of the user - if they are sponsor of the organisation
&lt;ul&gt;
&lt;li&gt;if they are sponsor&lt;/li&gt;
&lt;li&gt;add the username to the set of sponsors in Redis&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;org_name&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;applied-knowledge-systems&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;app&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;route&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;/oauth2/callback&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; oauth2_callback&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    code&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    access_token_url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;https://github.com/login/oauth/access_token&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    payload&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;client_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span&gt; client_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;client_secret&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span&gt; client_secret&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;code&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span&gt; code&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;        # &amp;#39;redirect_uri&amp;#39;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;state&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;uuid4&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hex&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    r&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; requests&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;post&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;access_token_url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;payload&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; headers&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;={&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Accept&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;application/json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;}&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    access_token&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;loads&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;access_token&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;    print&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;access_token&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    access_user_url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;https://api.github.com/user&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    response&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; requests&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;access_user_url&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; headers&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;={&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Authorization&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;token &lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39; +&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; access_token&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;response&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user_email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user_login&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;login&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # response=redirect(url_for(&amp;#39;login&amp;#39;,next=redirect_url()))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # response.set_cookie(&amp;#39;user_id&amp;#39;, str(user_id))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # response.set_cookie(&amp;#39;user_login&amp;#39;, str(user_login))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # return response&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    query&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;        viewer {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;            sponsorshipsAsSponsor(first: 100) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;            nodes {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                sponsorable {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                ... on User {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    email&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    url&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                ... on Organization {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    email&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                    url&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                tier {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                monthlyPriceInDollars&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                monthlyPriceInCents&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;                }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    response_graphql&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; requests&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;post&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;https://api.github.com/graphql&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;={&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; query&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;},&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; headers&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;={&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Authorization&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;token &lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39; +&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; access_token&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    response_graphql_data&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;response_graphql&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;json&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; isinstance&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;response_graphql_data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;viewer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;sponsorshipsAsSponsor&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;][&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;],&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; list&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;      if&lt;/span&gt;&lt;span&gt; response_graphql_data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;viewer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;sponsorshipsAsSponsor&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;][&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;nodes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;][&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;][&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;sponsorable&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;][&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;]&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;==&lt;/span&gt;&lt;span&gt;org_name&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;          # if user is a sponsor of Applied Knowledge System add them to set of sponsors&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;         redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;sadd&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;sponsors:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;org_name&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # if RedisJSON enabled:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # redis_client.json().set(f&amp;quot;user_details:{user_id}&amp;quot;, &amp;#39;$&amp;#39;, {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    #     &amp;#39;email&amp;#39;: user_email,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    #     &amp;#39;id&amp;#39;: user_id,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    #     &amp;#39;user_login&amp;#39;: user_login,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    #     &amp;#39;graphql&amp;#39;: response_graphql_data,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # }) &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    #if not&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;hset&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;user_details:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; mapping&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;={&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user_login&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_login&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; jsonify&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;status&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;: &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;success&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_email&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;        &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user_login&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_login&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;    }&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The API we are using for our sponsor-only feature is straightforward:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;app&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;route&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;/exclude&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; methods&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;POST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;GET&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;]&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; mark_node&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if&lt;/span&gt;&lt;span&gt; request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;method&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;POST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            node_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;json&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    else&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            node_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; session&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;Got user &lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; from session&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; request&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;cookies&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;        log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;Got user &lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; from cookie&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;sadd&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user:%s:mnodes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; %&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;node_id&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    response&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; jsonify&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;Finished &lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;node_id&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; response&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the only purpose of this API is to mark nodes as unimportant for the given user by adding nodes to RedisSet, and those nodes will be excluded from search API output. So far, everything was pretty standard: basic flask API and GitHub Social login flow. Now let&#39;s add Redis Enterprise and synchronise sponsors preferences.&lt;/p&gt;
&lt;h1 id=&quot;add-redis-enterprise&quot;&gt;Add Redis Enterprise&lt;/h1&gt;
&lt;p&gt;Why not use Redis Enterprise directly for everything?
The project is memory-heavy, with a lot of data and machine learning inside Redis. This allows to achieve state-of-the-art performance, but it also takes over 120 GB RAM (or as much RAM as you can give it), and 128 GB Redis Enterprise instance will exceed my budget for open-source project. Obviously if there will be enough sponsors we can move more functionality into Redis Enterprise, but for that we need to finish building basic blocks. Register on &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://redis.com/?utm_campaign=write_for_redis&quot;&gt;Redis.com&lt;/a&gt; cloud and create a database with the subscription.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/posts/github-oauth2/redis_enterprise_screen.png&quot; alt=&quot;Redis Enterprise&quot; /&gt;
Take a note host, port and password for Redis Enterprise and create docker enviroment file:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;cat&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; .env.gears&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;REDISENT_PWD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;123&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;REDISENT_PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;13444&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;REDISENT_HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;hostname.cloud.redislabs.com&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and create a docker compose with section passing .env.gears. Mine looks like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  redisgraph:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    image: redislabs/redismod&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    container_name: redisgears&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    hostname: redisgears&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    env_file:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      - ./.env.gears&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ports:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      - 127.0.0.1:9001:6379&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;synchronize-redis-oss-to-redis-enterprise-using-redisgears&quot;&gt;Synchronize Redis OSS to Redis Enterprise using RedisGears&lt;/h1&gt;
&lt;h2 id=&quot;synchronize-all-user-preferences&quot;&gt;Synchronize all user preferences&lt;/h2&gt;
&lt;p&gt;First flow:
We will be using RedisGears to synchronize all preferences with Redis Enterprise&lt;/p&gt;
&lt;div class=&quot;mermaid-wrap&quot;&gt;&lt;pre class=&quot;mermaid&quot;&gt;
flowchart LR
    id1(User Preferences Redis OSS) --&gt; redis_gears1(Redis Gears)--&gt; redise(Redis Enterprise)
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you are new to RedisGears, there is a pattern &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/RedisGears/rgsync/tree/master/examples/redis&quot;&gt;rgsync&lt;/a&gt; that covers exacly this use case, but I already have RedisGears, so I am going to build it step by step:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;# gears_sync_preferences.py&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; redis &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; os &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;environ&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # Get environment variables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PWD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redis&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;Redis&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; password&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; decode_responses&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; redis_client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; sync_users&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9D7CD8;font-style: italic;&quot;&gt;    global&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # Uncomment logs to check &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # log(str(record[&amp;#39;key&amp;#39;]))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # log(str(record[&amp;#39;value&amp;#39;]))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;hset&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;mapping&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; GB&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sync_users&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user_details:*&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;this is a &quot;batch&quot; mode for RedisGears, which is easier to debug than streams. Install gears-cli](https://github.com/RedisGears/gears-cli) with &lt;code&gt;pip install gears-cli&lt;/code&gt; run above script:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;gears-cli&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --host&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --port&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 9001&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; gears_sync_preferences.py&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --requirements&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; req_sync.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;where req_sync.txt&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;redis&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;3.5&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This RedisGears will copy all user&#39;s profiles into RedisEnterprise. Now let us add sponsors:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;# gears_sync_sponsors.py&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; remove_prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; text&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;startswith&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; redis &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; os &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;environ&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # Get environment variables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PWD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;HOST&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PORT&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redis&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;Redis&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; password&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; redis_client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; sync_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9D7CD8;font-style: italic;&quot;&gt;    global&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SMEMBERS&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    for&lt;/span&gt;&lt;span&gt; each_value&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;sadd&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;each_value&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; GB&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;KeysReader&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sync_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user:*&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But this one will sync all user&#39;s preferences, but we only need sponsors - let us add another feature of RedisGears - filter:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; remove_prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;text&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; text&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span&gt;text&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;startswith&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; redis &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; os &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;environ&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # Get environment variables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PWD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;    PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; os&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getenv&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;REDISENT_PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redis_client&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redis&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;Redis&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;HOST&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PORT&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;charset&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; password&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;PASSWORD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; decode_responses&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; redis_client&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; filter_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    org_name&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;applied-knowledge-systems&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user_id&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; remove_prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user:&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sponsor&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SISMEMBER&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;sponsors:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;org_name&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;user_id&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; bool&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sponsor&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; sync_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9D7CD8;font-style: italic;&quot;&gt;    global&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SMEMBERS&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    for&lt;/span&gt;&lt;span&gt; each_value&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;sadd&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;each_value&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; GB&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;filter_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sync_sponsors&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;run&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user:*&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;fetch-sponsor-s-preferences-back-to-redis-oss-from-redis-enterprise&quot;&gt;Fetch sponsor&#39;s preferences back to Redis OSS from Redis Enterprise&lt;/h2&gt;
&lt;p&gt;Then we are going to use &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20221123154317/https://oss.redis.com/redisgears/1.2/miss_event.html#fetch-data-on-keymiss-event&quot;&gt;Key miss events&lt;/a&gt; from Redis Gears to fetch data for all users:&lt;/p&gt;
&lt;div class=&quot;mermaid-wrap&quot;&gt;&lt;pre class=&quot;mermaid&quot;&gt;
flowchart LR
    redise(Redis Enterprise)
    redis_gears2(Redis Gears)--key miss---&gt;redise
    redis_gears2--&gt;redisOSS[Redis OSS]
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;and it&#39;s very easy, right from key miss example:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; fetch_data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; r&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9D7CD8;font-style: italic;&quot;&gt;    global&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;connecttoRedisEnterise&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;rconn&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;smembers&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;values&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    for&lt;/span&gt;&lt;span&gt; each_value&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; values&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;        execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SADD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;each_value&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;GB&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;fetch_data&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;register&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;prefix&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;user:*&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; commands&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;smember&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;],&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;eventTypes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;keymiss&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;],&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; mode&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;async_local&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is one more option - to turn fetch_data into the async call, by wrapping it into async/await, but Redis Enterprise is fairly fast, and I don&#39;t think it&#39;s worth adding an async call in this case. For curiosity, see the example &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/54e96ff7ef9fddbb1ad7c34d1fd5a4333a4d4c41/qasearch/qa_redisai_gear_map_keymiss_np.py#L21&quot;&gt;code&lt;/a&gt; in The Pattern repository.&lt;/p&gt;
&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;In this article, we walked through steps on how to create sponsor-specific &quot;nanoservices&quot; using RedisOSS, RedisGears and Redis Enterprise. This allows us to leverage the best of all worlds open source Redis, high availability and persistence with Redis Enterprise and RedisGears as the glue which holds everything together.&lt;/p&gt;
&lt;p&gt;This post is in collaboration with Redis.&lt;/p&gt;
&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20220808021840/https://creativewebspecialist.co.uk/2021/01/08/how-to-use-github-sponsors-to-help-monetize-your-software/&quot;&gt;How to use GitHub Sponsors to help monetize your software&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/community/community/discussions/3818&quot;&gt;Who sponsors this user?&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://gist.github.com/alexellis/6212c988189323dbb2806d1c7f7699ab&quot;&gt;Check sponsors.go - query whether a GitHub user is your sponsor at a given tier (dollar amount)&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://gist.github.com/xros/aba970d1098d916200d0acce8feb0251&quot;&gt;GitHub OAuth2 Gist&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://docs.github.com/en/graphql/overview/explorer&quot;&gt;GraphQL explorer&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
      </item>
      <item>
          <title>Benchmarks for BERT Large Question Answering inference for RedisAI and RedisGears</title>
          <pubDate>Thu, 16 Jun 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/bert-qa-benchmarking/</link>
          <guid>https://reference-architecture.ai/docs/bert-qa-benchmarking/</guid>
          <description xml:base="https://reference-architecture.ai/docs/bert-qa-benchmarking/">&lt;h2 id=&quot;summary-of-the-article&quot;&gt;Summary of the article&lt;/h2&gt;
&lt;p&gt;This article will explore the challenges and opportunities of deploying a large BERT Question Answering Transformer model(bert-large-uncased-whole-word-masking-finetuned-squad) from inside Huggingface, where &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://developer.redis.com/howtos/redisgears?utm_campaign=write_for_redis&quot;&gt;RedisGears&lt;/a&gt; and &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20220724124905/https://developer.redis.com/howtos/redisai/getting-started&quot;&gt;RedisAI&lt;/a&gt; perform heavy lifting while leveraging in-memory datastore Redis.&lt;/p&gt;
&lt;h2 id=&quot;why-do-we-need-redisai&quot;&gt;Why do we need RedisAI?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;In data science load, you want to load high-performance hardware as close to 100% as possible&lt;/li&gt;
&lt;li&gt;In user-facing load, you want to be able to distribute the load evenly, so it never reaches 100%, and client-facing servers can perform additional functions&lt;/li&gt;
&lt;li&gt;In data science, you prefer re-calculate results&lt;/li&gt;
&lt;li&gt;In a client-facing application, you prefer to cache results of calculation and fetch data from the cache as fast as possible to drive a seamless customer experience&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some numbers for inspiration and why to read this article:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;python3 transformers_plain_bert_qa.py &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;airborne transmission of respiratory infections is the lack of established methods for the detection of airborne respiratory microorganisms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10.351818372 seconds&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time curl -i -H &amp;quot;Content-Type: application/json&amp;quot; -X POST -d &amp;#39;{&amp;quot;search&amp;quot;:&amp;quot;Who performs viral transmission among adults&amp;quot;}&amp;#39; http://localhost:8080/qasearch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;real	0m0.747s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;user	0m0.004s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sys	0m0.000s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;
&lt;p&gt;BERT Question Answering inference works where the ML model selects an answer from the given text. In other words, BERT QA &quot;thinks&quot; through the following: &quot;What is the answer from the text, assuming the answer to the question exists within the paragraph selected.&quot;&lt;/p&gt;
&lt;p&gt;So it&#39;s important to select text potentially containing an answer. A typical pattern is to use Wikipedia data to build &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://lilianweng.github.io/posts/2020-10-29-odqa/&quot;&gt;Open Domain Question Answering&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Our QA system is a medical domain-specific question/answering pipeline, hence we need a first pipeline that turns data into a knowledge graph. This NLP pipeline is available at Redis LaunchPad, is fully &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern&quot;&gt;open source&lt;/a&gt;, and is described in &lt;a href=&quot;https://reference-architecture.ai/docs/nlp/&quot;&gt;a previous article&lt;/a&gt;. Here is a 5 minute &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.youtube.com/watch?v=VgJ8DTX5Mt4&quot;&gt;video&lt;/a&gt; describing it, and below you will find an architectural overview:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/featured.png&quot; alt=&quot;featured&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;bert-question-answering-pipeline-and-api&quot;&gt;BERT Question Answering pipeline and API&lt;/h1&gt;
&lt;p&gt;In the BERT QA pipeline (or in any other modern NLP inference task), there are two steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Tokenize text - turn text into numbers&lt;/li&gt;
&lt;li&gt;Run the inference - large matrix multiplication&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;With Redis, we have the opportunity to pre-compute everything and store it in memory, but how do we do it? Unlike with the summarization ML learning task, the question is not known in advance, so we can&#39;t pre-compute all possible answers. However, we can pre-tokenize all potential answers (i.e. all paragraphs in the dataset) using RedisGears:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; parse_sentence&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; redisAI&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;    import&lt;/span&gt;&lt;span&gt; numpy&lt;/span&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt; as&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9D7CD8;font-style: italic;&quot;&gt;    global&lt;/span&gt;&lt;span&gt; tokenizer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    if not&lt;/span&gt;&lt;span&gt; tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;loadTokeniser&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    hash_tag&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;{%s}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; %&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; hashtag&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    for&lt;/span&gt;&lt;span&gt; idx&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span&gt; value&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; sorted&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;lambda&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; item&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;item&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]))&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;encode&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; add_special_tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;False&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; max_length&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;511&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; truncation&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; return_tensors&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sep_token_id&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;astype&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;int64&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        tensor&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;createTensorFromBlob&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;INT64&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;tobytes&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        key_prefix&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;sentence:&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        sentence_key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;remove_prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;record&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;key_prefix&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        token_key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;tokenized:bert:qa:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sentence_key&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;idx&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;setTensorInKey&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;token_key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; tensor&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;        execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SADD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;processed_docs_stage3_tokenized&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tag&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; token_key&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;See the &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/156633b9934f1243775671ce6c18ff2bf471c0ce/qasearch/tokeniser_gears_redisai.py#L17&quot;&gt;full code on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Then for each Redis Cluster shard, we pre-load the BERT QA model by downloading, exporting it into torchscript, then loading it into each shard:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; load_bert&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    model_file&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;traced_bert_qa.pt&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    with&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; open&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;model_file&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;rb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        model&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;read&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    startup_nodes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; = [{&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;30001&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;}, {&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;: &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;:&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;30002&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;}, {&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;host&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;:&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;port&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;:&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;30003&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;}]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cc&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; ClusterClient&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;startup_nodes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; startup_nodes&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    hash_tags&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; cc&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;execute_command&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;RG.PYEXECUTE&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;,  &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;gb = GB(&amp;#39;ShardsIDReader&amp;#39;).map(lambda x:hashtag()).run()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;    print&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tags&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    for&lt;/span&gt;&lt;span&gt; hash_tag&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; in&lt;/span&gt;&lt;span&gt; hash_tags&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;        print&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Loading model bert-qa{%s}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot; %&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tag&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;decode&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        cc&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelset&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;bert-qa{%s}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39; %&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tag&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;decode&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;TORCH&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;CPU&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; model&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;        print&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;cc&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;infoget&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;bert-qa{%s}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39; %&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tag&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;decode&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;utf-8&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/156633b9934f1243775671ce6c18ff2bf471c0ce/qasearch/export_load_bert.py&quot;&gt;full code is available on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;And when a question comes from the user, we tokenize and append the question to the list of potential answers before running the RedisAI model:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    token_key&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;tokenized:bert:qa:&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;sentence_key&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # encode question&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input_ids_question&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;encode&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;question&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; add_special_tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; truncation&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; return_tensors&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;getTensorFromKey&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;token_key&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input_ids_context&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;to_np&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;int64&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # merge (append) with potential answer, context - is pre-tokenized paragraph&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;append&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;input_ids_question&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;input_ids_context&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    attention_mask&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]*&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;input_ids&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input_idss&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;input_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    num_seg_a&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;input_ids_question&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    num_seg_b&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;input_ids_context&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    token_type_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]*&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;num_seg_a&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; + [&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;]*&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;num_seg_b&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # create actual model runner for RedisAI&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;createModelRunner&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;bert-qa&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;hash_tag&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # make sure all types are correct&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    input_idss_ts&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;createTensorFromBlob&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;INT64&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; input_idss&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; input_idss&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;tobytes&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    attention_mask_ts&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;createTensorFromBlob&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;INT64&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; attention_mask&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; attention_mask&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;tobytes&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    token_type_ids_ts&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span&gt;redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;createTensorFromBlob&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;INT64&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; token_type_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;shape&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; token_type_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;tobytes&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerAddInput&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;input_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; input_idss_ts&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerAddInput&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;attention_mask&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; attention_mask_ts&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerAddInput&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;token_type_ids&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; token_type_ids_ts&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerAddOutput&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;answer_start_scores&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerAddOutput&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;, &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;answer_end_scores&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;    # run RedisAI model runner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    res&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; await&lt;/span&gt;&lt;span&gt; redisAI&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;modelRunnerRunAsync&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;modelRunner&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer_start_scores&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;to_np&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;float32&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer_end_scores&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; to_np&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;res&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;float32&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer_start&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;argmax&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;answer_start_scores&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer_end&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; np&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;argmax&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;answer_end_scores&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    answer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;convert_tokens_to_string&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;tokenizer&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;convert_ids_to_tokens&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;input_ids&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;answer_start&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;answer_end&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;skip_special_tokens&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; True&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;    log&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Answer &lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;+&lt;/span&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;answer&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;    return&lt;/span&gt;&lt;span&gt; answer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Checkout the &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/156633b9934f1243775671ce6c18ff2bf471c0ce/qasearch/qa_redisai_keymiss_no_cache_np.py#L34&quot;&gt;full code, available on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The process for making a BERT QA API call looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/diagrams_02.png&quot; alt=&quot;Architecture Diagram for BERT QA RedisGears and RedisAI&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Here I use two cool features of RedisGears: capturing events on key miss and using async/await to run RedisAI on each shard without locking the primary thread - so that Redis Cluster can continue to serve other customers. For benchmarks, caching responses from RedisAI is &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/156633b9934f1243775671ce6c18ff2bf471c0ce/qasearch/qa_redisai_keymiss_no_cache_np.py#L29&quot;&gt;disabled&lt;/a&gt;. If you are getting response times in nanoseconds on the second call rather then milliseconds, check to make sure the line linked above is commented out.&lt;/p&gt;
&lt;h1 id=&quot;running-the-benchmark&quot;&gt;Running the Benchmark&lt;/h1&gt;
&lt;p&gt;Pre-requisites for running the benchmark:&lt;/p&gt;
&lt;p&gt;Assuming you are running Debian or Ubuntu and have Docker and docker-compose installed (or can create a virtual environment via conda), run the following commands:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;git clone --recurse-submodules https://github.com/applied-knowledge-systems/the-pattern.git&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;cd the-pattern&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;./bootstrap_benchmark.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The above commands should end with a curl call to the qasearch API, since Redis caching is disabled for the benchmark.&lt;/p&gt;
&lt;p&gt;Next, invoke curl like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;time curl -i -H &amp;quot;Content-Type: application/json&amp;quot; -X POST -d &amp;#39;{&amp;quot;search&amp;quot;:&amp;quot;Who performs viral transmission among adults&amp;quot;}&amp;#39; http://localhost:8080/qasearch&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Expect the following output, or something similar based on your runtime environment:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;HTTP/1.1 200 OK&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Server: nginx/1.18.0 (Ubuntu)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Date: Sun, 29 May 2022 12:05:39 GMT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Content-Type: application/json&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Content-Length: 2120&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Connection: keep-alive&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&amp;quot;links&amp;quot;:[{&amp;quot;created_at&amp;quot;:&amp;quot;2002&amp;quot;,&amp;quot;rank&amp;quot;:13,&amp;quot;source&amp;quot;:&amp;quot;C0001486&amp;quot;,&amp;quot;target&amp;quot;:&amp;quot;C0152083&amp;quot;}],&amp;quot;results&amp;quot;:[{&amp;quot;answer&amp;quot;:&amp;quot;adenovirus&amp;quot;,&amp;quot;sentence&amp;quot;:&amp;quot;The medium of 40 T150 flasks of adenovirus transducer dec CAR CHO cells yielded 0 5 1 my of purified msCEACAM1a 1 4 protein&amp;quot;,&amp;quot;sentencekey&amp;quot;:&amp;quot;sentence:PMC125375.xml:{mG}:202&amp;quot;,&amp;quot;title&amp;quot;:&amp;quot;Crystal structure of murine sCEACAM1a[1,4]: a coronavirus receptor in the CEA family&amp;quot;}] OUTPUT_REDUCTED}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I modified the output of API for the benchmark to return results from all shards - even if the answer is empty, in the run above five shards return answers, overall API call response under second with all additional hops to search in RedisGraph.&lt;/p&gt;
&lt;p&gt;I modified the output of the API for the benchmark to return results from all shards - even if the answer is empty. In the run above five shards return answers. The overall API call response takes less than one second with all additional hops to search in RedisGraph!&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/diagrams_01.png&quot; alt=&quot;Architecture Diagram for BERT QA API call&quot; /&gt;&lt;/p&gt;
&lt;h1 id=&quot;deep-dive-into-the-benchmark&quot;&gt;Deep Dive into the Benchmark&lt;/h1&gt;
&lt;p&gt;Let&#39;s dig deeper into what&#39;s happening under the hood:&lt;/p&gt;
&lt;p&gt;You should have a sentence key with shard id, which you get by looking at the &quot;Cache key&quot; from &lt;code&gt;docker logs -f rgcluster&lt;/code&gt;. In my setup the cache key is, &quot;bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults&quot;. If you think it looks like a function call it&#39;s because it is a function call. It is triggered if the key isn&#39;t present in the Redis Cluster, which for the benchmark will be every time since if you remember we disabled caching the output.&lt;/p&gt;
&lt;p&gt;One more thing to figure out from the logs is the port of the shard corresponding to the hashtag, also known as the &lt;code&gt;shard id&lt;/code&gt;. It is the text found in betweeen the curly brackets – looks like &lt;code&gt;{6fd}&lt;/code&gt; above. The same will be in the output for the &lt;code&gt;export_load&lt;/code&gt; script. In my case the cache key was found in &quot;30012.log&quot;, so my port is 30012.&lt;/p&gt;
&lt;p&gt;Next I run the following command:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;redis-cli -c -p 300012 -h 127.0.0.1 get &amp;quot;bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and then run the benchmark:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;redis-benchmark -p 30012 -h 127.0.0.1 -n 10 get &amp;quot;bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;====== get bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults ======&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  10 requests completed in 0.04 seconds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  50 parallel clients&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  3 bytes payload&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  keep alive: 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10.00% &amp;lt;= 41 milliseconds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;100.00% &amp;lt;= 41 milliseconds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;238.10 requests per second&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you are wondering, &lt;code&gt;-n&lt;/code&gt; = number of times. In this case we run the benchmark 10 times. You can also add:&lt;/p&gt;
&lt;p&gt;– &lt;code&gt;csv&lt;/code&gt; if you want to output in CSV format&lt;/p&gt;
&lt;p&gt;– &lt;code&gt;precision 3&lt;/code&gt; if you want more decimals in the ms&lt;/p&gt;
&lt;p&gt;More information about the benchmarking tool can be found on the &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://redis.io/topics/benchmarks&quot;&gt;redis.io Benchmarks page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;if you don&#39;t have redis-utils installed locally, you can use Docker as follows:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;docker&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; exec&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -it&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; rgcluster /bin/bash&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;redis-benchmark&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 30012&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -h&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; get&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;====== get bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults ======&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  10&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; requests completed in&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1.75&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; seconds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  50&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; parallel clients&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  99&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; bytes payload&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  keep&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; alive:&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  host&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; configuration&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;save&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  host&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; configuration&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;appendonly&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;: no&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  multi-thread:&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; no&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;Latency&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; by percentile distribution:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;0.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 243.711&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;50.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 987.135&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 5&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;75.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1577.983&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 8&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;87.500%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1662.975&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 9&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;93.750%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1744.895&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 10&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;100.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1744.895&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 10&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;Cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; distribution of latencies:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;0.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 0.103&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 0&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;10.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 244.223&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;20.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 409.343&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 2&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;30.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 575.487&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 3&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;40.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 821.247&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 4&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;50.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 987.135&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 5&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;60.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1157.119&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 6&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;70.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1497.087&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 7&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;80.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1577.983&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 8&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;90.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1662.975&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 9&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;100.000%&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 1744.895&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; milliseconds&lt;/span&gt;&lt;span&gt; (cumulative&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; count&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 10&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;Summary:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  throughput&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; summary:&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 5.73&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; requests per second&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;  latency&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; summary&lt;/span&gt;&lt;span&gt; (msec):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;          avg&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;       min       p50       p95       p99       max&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;     1067.296&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;   243.584   987.135  1744.895  1744.895  1744.895&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The platform only has 20 articles and 8 Redis nodes (4 masters + 4 slaves), so relevance would be wrong and it doesn&#39;t need a lot of memory.&lt;/p&gt;
&lt;h2 id=&quot;ai-info&quot;&gt;AI.INFO&lt;/h2&gt;
&lt;p&gt;Now let&#39;s check how long our RedisAI model runs on the &lt;code&gt;{6fd}&lt;/code&gt; shard:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;127.0.0.1:30012&amp;gt; AI.INFO bert-qa{6fd}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 1) &amp;quot;key&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 2) &amp;quot;bert-qa{6fd}&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 3) &amp;quot;type&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 4) &amp;quot;MODEL&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 5) &amp;quot;backend&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 6) &amp;quot;TORCH&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 7) &amp;quot;device&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 8) &amp;quot;CPU&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 9) &amp;quot;tag&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10) &amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;11) &amp;quot;duration&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;12) (integer) 8928136&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;13) &amp;quot;samples&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;14) (integer) 58&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;15) &amp;quot;calls&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;16) (integer) 58&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;17) &amp;quot;errors&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;18) (integer) 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;bert-qa{6fd}&lt;/code&gt; is the key of the actual (very large) model saved. The &lt;code&gt;AI.INFO&lt;/code&gt; command gives us a cumulative duration of 8928136 microseconds and 58 calls, which is approximately 153 milliseconds per call.&lt;/p&gt;
&lt;p&gt;Let&#39;s double-check to make sure that&#39;s right by resetting the stats and then re-runnning the benchmark.&lt;/p&gt;
&lt;p&gt;First, reset the stats:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;127.0.0.1:30012&amp;gt; AI.INFO bert-qa{6fd} RESETSTAT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;OK&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;127.0.0.1:30012&amp;gt; AI.INFO bert-qa{6fd}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 1) &amp;quot;key&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 2) &amp;quot;bert-qa{6fd}&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 3) &amp;quot;type&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 4) &amp;quot;MODEL&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 5) &amp;quot;backend&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 6) &amp;quot;TORCH&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 7) &amp;quot;device&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 8) &amp;quot;CPU&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 9) &amp;quot;tag&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10) &amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;11) &amp;quot;duration&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;12) (integer) 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;13) &amp;quot;samples&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;14) (integer) 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;15) &amp;quot;calls&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;16) (integer) 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;17) &amp;quot;errors&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;18) (integer) 0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then, re-run the benchmark:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;redis-benchmark -p 30012 -h 127.0.0.1 -n 10 get &amp;quot;bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;====== get bertqa{6fd}_PMC169038.xml:{6fd}:33_Who performs viral transmission among adults ======&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  10 requests completed in 1.78 seconds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  50 parallel clients&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  99 bytes payload&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  keep alive: 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  host configuration &amp;quot;save&amp;quot;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  host configuration &amp;quot;appendonly&amp;quot;: no&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  multi-thread: no&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Latency by percentile distribution:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0.000% &amp;lt;= 188.927 milliseconds (cumulative count 1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50.000% &amp;lt;= 995.839 milliseconds (cumulative count 5)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;75.000% &amp;lt;= 1606.655 milliseconds (cumulative count 8)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;87.500% &amp;lt;= 1692.671 milliseconds (cumulative count 9)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;93.750% &amp;lt;= 1779.711 milliseconds (cumulative count 10)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;100.000% &amp;lt;= 1779.711 milliseconds (cumulative count 10)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Cumulative distribution of latencies:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;0.000% &amp;lt;= 0.103 milliseconds (cumulative count 0)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10.000% &amp;lt;= 189.183 milliseconds (cumulative count 1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;20.000% &amp;lt;= 392.191 milliseconds (cumulative count 2)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;30.000% &amp;lt;= 540.159 milliseconds (cumulative count 3)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;40.000% &amp;lt;= 896.511 milliseconds (cumulative count 4)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;50.000% &amp;lt;= 996.351 milliseconds (cumulative count 5)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;60.000% &amp;lt;= 1260.543 milliseconds (cumulative count 6)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;70.000% &amp;lt;= 1456.127 milliseconds (cumulative count 7)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;80.000% &amp;lt;= 1606.655 milliseconds (cumulative count 8)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;90.000% &amp;lt;= 1692.671 milliseconds (cumulative count 9)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;100.000% &amp;lt;= 1779.711 milliseconds (cumulative count 10)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Summary:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  throughput summary: 5.62 requests per second&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  latency summary (msec):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;          avg       min       p50       p95       p99       max&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;     1080.454   188.800   995.839  1779.711  1779.711  1779.711&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now check the stats again:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AI.INFO bert-qa{6fd}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 1) &amp;quot;key&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 2) &amp;quot;bert-qa{6fd}&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 3) &amp;quot;type&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 4) &amp;quot;MODEL&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 5) &amp;quot;backend&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 6) &amp;quot;TORCH&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 7) &amp;quot;device&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 8) &amp;quot;CPU&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; 9) &amp;quot;tag&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;10) &amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;11) &amp;quot;duration&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;12) (integer) 1767749&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;13) &amp;quot;samples&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;14) (integer) 20&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;15) &amp;quot;calls&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;16) (integer) 20&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;17) &amp;quot;errors&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;18) (integer) 0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we get 88387.45 microseconds per call ~0.088387 seconds, which is pretty fast! Also, considering we started with 10 seconds per call, I think the benefits of using RedisAI in combination with RedisGears are pretty obvious. However, the trade-off is high memory usage.&lt;/p&gt;
&lt;p&gt;There are many ways to optimize this deployment. For example, you can add a FP16 quantization and ONNX runtime. If you would like to try that, &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-api/blob/7bcf021e537dc8d453036730f0a993dd52e1781f/qasearch/export_load_bert.py&quot;&gt;this script&lt;/a&gt; will be a good starting point.&lt;/p&gt;
&lt;h1 id=&quot;using-grafana-to-monitor-redisgears-throughput-cpu-and-memory-usage&quot;&gt;Using Grafana to monitor RedisGears throughput, CPU, and Memory usage&lt;/h1&gt;
&lt;p&gt;Thanks to the contribution of &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20221231201518/https://volkovlabs.com/from-a-basic-redistimeseries-data-source-to-2-million-downloads-in-grafana-marketplace-9921ed9ac5a&quot;&gt;Mikhail Volkov&lt;/a&gt;, we can now observe RedisGears and RedisGraph throughput and memory consumption using Grafana. When you cloned repository it started Graphana Docker, which has pre-build templates to monitor RedisCluster, including RedisGears and RedisAI, and Graph - which is Redis with RedisGraph. &quot;The Pattern&quot; dashboard provides an overview, with all the key benchmark metrics you care about:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/graphana_redis_graph.png&quot; alt=&quot;Grafana for RedisGraph&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/graphana_cluster_overview.png&quot; alt=&quot;Grafana for RedisCluster&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This post is in collaboration with Redis.&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Capability Map (2020-2022)</title>
          <pubDate>Thu, 16 Jun 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/legacy-capability-map/</link>
          <guid>https://reference-architecture.ai/docs/legacy-capability-map/</guid>
          <description xml:base="https://reference-architecture.ai/docs/legacy-capability-map/">&lt;h1 id=&quot;introduction&quot;&gt;Introduction&lt;/h1&gt;
&lt;p&gt;There are tools for advanced analytics, including free ones from Google and Kaggle.&lt;/p&gt;
&lt;p&gt;There are well-known and validated deployment architectures for applications and the cloud.&lt;/p&gt;
&lt;p&gt;Yet the number of practical applications is still tiny, and they retained niche implementations.
While the benefits of AI are clear, there are still many gaps in AI architecture that need to be filled. For example, there is a gap between analytical tools and verified architectures for real-time deployments. This gap often stems from a lack of specific reference architectures and patterns, demonstrating the trade-offs between technologies, libraries, and tools.&lt;/p&gt;
&lt;p&gt;Let&#39;s bridge the gap in knowledge and drive a connection between science and engineering to make fast, efficient, and practical AI deployments.&lt;/p&gt;
&lt;p&gt;Three things need to be in place to build an AI product:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;AI Product itself&lt;/li&gt;
&lt;li&gt;Core Capabilities required to build AI/ML product&lt;/li&gt;
&lt;li&gt;Enabling capabilities&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I will use &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://thepattern.digital/&quot;&gt;The Pattern&lt;/a&gt;, my &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://redis.com/blog/build-on-redis-hackathon-winners/&quot;&gt;Build on Redis Hackathon&lt;/a&gt; prize-winning &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern&quot;&gt;open source&lt;/a&gt; project to illustrate how the capabilities below can be implemented and invite you to &lt;a href=&quot;https://reference-architecture.ai/docs/contribution/&quot;&gt;contribute&lt;/a&gt; or &lt;a href=&quot;https://reference-architecture.ai/docs/donate/&quot;&gt;donate&lt;/a&gt;.
The diagrams below are clickable.&lt;/p&gt;
&lt;h1 id=&quot;ai-product&quot;&gt;AI Product&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;/docs/ai-product/&quot;&gt;&lt;img src=&quot;/images/ai_product.drawio.svg&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1 id=&quot;core-capabilities-for-ai-ml&quot;&gt;Core capabilities for AI/ML&lt;/h1&gt;
&lt;div class=&quot;mermaid-wrap&quot;&gt;&lt;pre class=&quot;mermaid&quot;&gt;
flowchart LR; 
subgraph &quot; &quot;
  data_intake(Data Acquisition);
  data_preprocessing(Data Preprocessing);
  data_validation(Data Validation);
  data_streaming(Data Streaming);
  ai_ml_pipe(AI ML Pipeline &lt;br/&gt; Model Training/Test/Validation);
  kg(Knowledge Graph);
  ML_inference(ML Inference);
  interaction(Interaction Layer&lt;br/&gt;Voice/VR/AR/Meta);
  click data_intake &quot;/docs/intake/&quot; &quot;Data Acquisition&quot;
  click ML_inference &quot;/docs/bert-qa-benchmarking/&quot; &quot;BERT Large Question Answering&quot;
  click kg &quot;/docs/nlp/#what-is-a-knowledge-graph&quot; &quot;Knowledge Graph&quot;
  click data_preprocessing &quot;/docs/nlp/#redisgears-for-nlp-pre-processing&quot; &quot;Data pre-processing&quot;
  click data_streaming &quot;/docs/nlp/#goal&quot; &quot;Data Streaming&quot;
  click ai_ml_pipe &quot;/docs/nlp/#overall-architecture-overview-components-diagram&quot; &quot;Overall ML pipeline&quot;
end
&lt;/pre&gt;&lt;/div&gt;
&lt;h1 id=&quot;enabling-capabilities&quot;&gt;Enabling Capabilities&lt;/h1&gt;
&lt;div class=&quot;mermaid-wrap&quot;&gt;&lt;pre class=&quot;mermaid&quot;&gt;
flowchart LR;
subgraph 2 [Enabling Capabilities]
  subgraph &quot; &quot;
D1[Data Governance]
D2[Data Quality Management]
D3[Metadata Management]
click D3 &quot;/docs/metadata/&quot; &quot;Metadata Management&quot;
end
subgraph &quot; &quot;
  id2[ML performance and bias monitoring];
  id3[Application Performance Monitoring];
  id4[Hardware Performance Monitoring];
  click id3 &quot;/docs/bert-qa-benchmarking/#running-the-benchmark&quot; &quot;Running Benchmarks&quot;
  click id4 &quot;/docs/bert-qa-benchmarking/#using-grafana-to-monitor-redisgears-throughput-cpu-and-memory-usage&quot; &quot;CPU and Memory Benchmarks&quot;
end
subgraph &quot; &quot;
  id5[DevOps: Continuous Integration/Continuous Deployment];
  c1[Configuration management]
  c2[Collaboration and knowledge management tooling]
  c3[Change Management]
end 
  subgraph 3 [Self Serving Infrastructure]
    s1[Computing Infrastructure]
    s2[Serving infrastructure]
  end
  end
  style 2 fill:#485fc754,stroke:#333,stroke-width:4px;
&lt;/pre&gt;&lt;/div&gt;
</description>
      </item>
      <item>
          <title>Announcing Reference Architecture for AI</title>
          <pubDate>Thu, 16 Jun 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/posts/post-0/</link>
          <guid>https://reference-architecture.ai/posts/post-0/</guid>
          <description xml:base="https://reference-architecture.ai/posts/post-0/">&lt;p&gt;There are tools for advanced analytics, including free ones from Google and Kaggle.&lt;/p&gt;
&lt;p&gt;There are well-known and validated deployment architectures for applications and the cloud.&lt;/p&gt;
&lt;p&gt;Yet the number of practical applications is still tiny, and they retained niche implementations.
While the benefits of AI are clear, there are still many gaps in AI architecture that need to be filled. For example, there is a gap between analytical tools and verified architectures for real-time deployments. This gap often stems from a lack of specific reference architectures and patterns, demonstrating the trade-offs between technologies, libraries, and tools.&lt;/p&gt;
&lt;p&gt;Let&#39;s bridge the gap in knowledge and drive a connection between science and engineering to make fast, efficient, and practical AI deployments.
Three things need to be in place to build an AI product:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;AI Product itself&lt;/li&gt;
&lt;li&gt;Core Capabilities required to build AI/ML product&lt;/li&gt;
&lt;li&gt;Enabling capabilities&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I will use &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://thepattern.digital/&quot;&gt;The Pattern&lt;/a&gt;, my [“Build on Redis&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://redis.com/blog/build-on-redis-hackathon-winners/&quot;&gt;” Hackathon &lt;/a&gt;prize-winning &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern&quot;&gt;open source&lt;/a&gt;](https://github.com/applied-knowledge-systems/the-pattern) project, to illustrate how the capabilities below can be implemented and invite you to &lt;a href=&quot;https://reference-architecture.ai/docs/contribution/&quot;&gt;contribute&lt;/a&gt; or &lt;a href=&quot;https://reference-architecture.ai/docs/donate/&quot;&gt;donate&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We launch in two full-featured articles - &lt;a href=&quot;https://reference-architecture.ai/docs/nlp/&quot;&gt;NLP ML pipeline for&lt;/a&gt; turning unstructured JSON text into a knowledge graph and fresh off the press &lt;a href=&quot;https://reference-architecture.ai/docs/bert-qa-benchmarking/&quot;&gt;Benchmarks for BERT Large Question Answering inference for RedisAI and RedisGears&lt;/a&gt; with Grafana Dashboards by &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20221231201518/https://volkovlabs.com/from-a-basic-redistimeseries-data-source-to-2-million-downloads-in-grafana-marketplace-9921ed9ac5a&quot;&gt;Mikhail Volkov&lt;/a&gt;&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Building a Pipeline for Natural Language Processing using RedisGears</title>
          <pubDate>Sat, 28 May 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/nlp/</link>
          <guid>https://reference-architecture.ai/docs/nlp/</guid>
          <description xml:base="https://reference-architecture.ai/docs/nlp/">&lt;h2 id=&quot;goal&quot;&gt;Goal&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Disclaimer&lt;/em&gt; originally published in collaboration with &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/ajeetraina&quot;&gt;Ajeet Raina&lt;/a&gt; on &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://developer.redis.com/howtos/nlp/&quot;&gt;Developer.Redis.Com&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In this tutorial, you will learn how to build a pipeline for  Natural Language Processing(NLP) using &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://developer.redis.com/howtos/redisgears&quot;&gt;RedisGears&lt;/a&gt;. For this demonstration, we will be leveraging the Kaggle CORD19 datasets. The implementation is designed to avoid running out of memory, leveraging Redis Cluster and RedisGears, where the use of RedisGears allows for processing data on storage without the need to move data in and out of the Redis Cluster—using Redis Cluster as data fabric. Redis Cluster allows for horizontal scalability up to 1000 nodes, and together with RedisGears, provides a distributed system where data science/ML engineers can focus on processing steps, without the worry of writing tons of scaffoldings for distributed calculations.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/nlp/nlparch.png&quot; alt=&quot;nlp&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This project was built with the aim to make it easier for other people to contribute and build better information and knowledge management products.&lt;/p&gt;
&lt;h2 id=&quot;why-data-scientists-uses-redisgears&quot;&gt;Why data scientists uses RedisGears?&lt;/h2&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://redis.com/modules/redis-gears/&quot;&gt;RedisGears&lt;/a&gt; have enormous potential, particularly for text processing—you can process your data “on data” without needing to move them in and out of memory. Summary of the important points:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In Memory storage (Horizontally scalable if it’s Redis cluster)&lt;/li&gt;
&lt;li&gt;Processing of data (on data) without need to move in and out&lt;/li&gt;
&lt;li&gt;Gears - like Spark on Hadoop, process data intelligently on storage(in-memory) without need to move data in and out&lt;/li&gt;
&lt;li&gt;Redis in cluster mode with RedisGears and python enabled takes 20 MB RAM. Think how much more data you can shuffle into your laptop or server.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-is-a-knowledge-graph&quot;&gt;What is a knowledge graph?&lt;/h2&gt;
&lt;p&gt;Today, we live in the world of new systems that operate not just files, folders, or web pages, but entities with their properties and relationships between them, organized into hierarchies of classes and categories. These systems are used everywhere from the military-industrial complex to our everyday lives. Palantir, Primer, and other data companies enable massive intelligence and counterintelligence projects in military and security forces, Quid and RecordedFuture enable competitive analytics, Bottlenose and similar enterprises enable online reputation analytics. Microsoft Graph enables new kinds of productivity apps for the enterprises, Google Knowledge Graph and Microsoft’s Satori enable everyday search queries, and together with Amazon Information Graph they power corresponding AI assistants by enabling them to answer questions about the world facts&lt;/p&gt;
&lt;p&gt;All these (and many other more specialized) systems are used in different domains, but all of them use Knowledge Graphs as their foundation.&lt;/p&gt;
&lt;p&gt;Knowledge graphs are one of the best ways to connect and make sense out of information from different data sources, following the motto of one of the vendors— &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.poolparty.biz/news-events/knowledge-graphs-connecting-dots-increasingly-complex-world/&quot;&gt;“It’s about things not strings”&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Knowledge Graph consists of thesaurus, taxonomy and ontology. In this pipeline I assume knowledge is captured in medical metathesaurus &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.nlm.nih.gov/research/umls/index.html&quot;&gt;UMLS&lt;/a&gt; and concepts in text are related if they are part of the same sentence, therefore concept become node, their relationship becomes edge:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/nlp/concepts1.png&quot; alt=&quot;concepts1&quot; /&gt;
&lt;img src=&quot;https://reference-architecture.ai/docs/nlp/concepts2.png&quot; alt=&quot;concepts2&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Concepts have CUI (Concept Unique Identifiers) and those will be primary keys in nodes, linked to UMLS thesaurus. For example, if you search, “How does temperature and humidity affect the transmission of 2019-nCoV?” on the demo website  &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http://thepattern.digital&quot;&gt;http://thepattern.digital/&lt;/a&gt; and move slider to 1996, there is an edge-connecting transmission (C5190195) and birth (C5195639) and the part of sentence matched, “the rate of transmission to an infant born to,” from the report titled, “Afebrile Pneumonia in infants.”&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/nlp/concepts3.png&quot; alt=&quot;concepts3&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;redisgears-for-nlp-pre-processing&quot;&gt;RedisGears for NLP pre-processing&lt;/h2&gt;
&lt;h3 id=&quot;overall-architecture-overview-components-diagram&quot;&gt;Overall Architecture Overview (Components Diagram)&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://reference-architecture.ai/docs/nlp/component_diagram.png&quot; alt=&quot;component_diagram&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Intake step - is very simple put all JSON records into RedisCluster, then NLP pipeline starts processing all records, code is &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform/blob/main/RedisIntakeRedisClusterSample.py&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&quot;how-does-the-nlp-pipeline-steps-fit-into-redisgears&quot;&gt;How does the NLP pipeline steps fit into RedisGears?&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;For each record — detect language (discard non English), it’s &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20240318030547/https://oss.redis.com/redisgears/operations.html#filter&quot;&gt;filter&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Map paragraphs into a sentence — &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20240318030547/https://oss.redis.com/redisgears/operations.html#flatmap&quot;&gt;flatmap&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sentences spellchecker — it’s &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20240318030547/https://oss.redis.com/redisgears/operations.html#map&quot;&gt;map&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save sentences into hash — &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://web.archive.org/web/20240318030547/https://oss.redis.com/redisgears/operations.html#processor&quot;&gt;processor&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;step-1-pre-requisite&quot;&gt;Step 1. Pre-requisite&lt;/h3&gt;
&lt;p&gt;Ensure that you install virtualenv in your system&lt;/p&gt;
&lt;h3 id=&quot;step-2-clone-the-repository&quot;&gt;Step 2. Clone the repository&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; git&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; clone&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --recurse-submodules&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; https://github.com/applied-knowledge-systems/the-pattern.git&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; cd&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; the-pattern&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;step-3-bring-up-the-application&quot;&gt;Step 3. Bring up the application&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; docker-compose&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -f&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; docker-compose.dev.yml up&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; --build -d&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;step-4-apply-cluster-configuration-settings&quot;&gt;Step 4. Apply cluster configuration settings&lt;/h3&gt;
&lt;p&gt;You can deploy PyTorch and spacy to run on RedisGears.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; bash&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; post_start_dev.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;For Data science-focused deployment, RedisCluster should be in HA mode with at least one slave for each master.
One need to change a few default parameters for rgcluster to accommodate the size of PyTorch and spacy libraries (each over 1GB zipped), gist with settings.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;step-5-create-or-activate-python-virtual-environment&quot;&gt;Step 5. Create or activate Python virtual environment&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; cd&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; ./the-pattern-platform/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;step-6-create-new-environment&quot;&gt;Step 6. Create new environment&lt;/h3&gt;
&lt;p&gt;You can create it via&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; conda&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; create&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -n&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; pattern_env python=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;3.8&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;Alternatively, you can activate by using the below CLI:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #0DB9D7;&quot;&gt; source&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; ~/venv_cord19/bin/activate&lt;/span&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt; #or create new venv&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; pip&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; install&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; requirements.txt&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;step-7-run-pipeline&quot;&gt;Step 7. Run pipeline&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; bash cluster_pipeline.sh&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;step-8-validating-the-functionality-of-the-nlp-pipeline&quot;&gt;Step 8. Validating the functionality of the NLP pipeline&lt;/h3&gt;
&lt;p&gt;Wait for a bit and then check:&lt;/p&gt;
&lt;h3 id=&quot;verifying-redis-graph-populated&quot;&gt;Verifying Redis Graph populated:&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; redis-cli&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 9001&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -h&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; GRAPH.QUERY cord19medical&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;MATCH (n:entity) RETURN count(n) as entity_count&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; redis-cli&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -p&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 9001&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -h&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt; 127.0.0.1&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; GRAPH.QUERY cord19medical&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;MATCH (e:entity)-[r]-&amp;gt;(t:entity) RETURN count(r) as edge_count&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;checking-api-responds&quot;&gt;Checking API responds:&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; curl&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -i -H&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;Content-Type: application/json&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -X&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt; POST&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; -d&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;{&amp;quot;search&amp;quot;:&amp;quot;How does temperature and humidity affect the transmission of 2019-nCoV&amp;quot;}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt; http://localhost:8080/gsearch&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;walkthrough&quot;&gt;Walkthrough&lt;/h2&gt;
&lt;p&gt;While RedisGears allows to deploy and run Machine Learning libraries like &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/AlexMikhalev/cord19redisknowledgegraph/blob/master/spacy_sentences_geared.py&quot;&gt;spacy&lt;/a&gt; and &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/AlexMikhalev/cord19redisknowledgegraph/blob/master/tokenizer_bert_geared.py&quot;&gt;BERT transformers&lt;/a&gt;, the solution above uses simpler approach:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; GB&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;KeysReader&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;filter&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;filter_language&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;flatmap&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;parse_paragraphs&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;spellcheck_sentences&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;save_sentences&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; gb&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;register&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;paragraphs:*&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;keyTypes&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=[&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;string&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;hash&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;],&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; mode&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;async_local&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is the overall pipeline: those 7 lines allow you to run logic in a distributed cluster or on a single machine using all available CPUs - no changes required until you need to scale over more 1000 nodes. I use KeysReader registered for namespace paragraphs for all strings or hashes. My pipeline would need to run in async mode. For data scientists, I would recommend using gb.run to make sure gears function work and it will run in batch mode and then change it to register - to capture new data. By default, functions will return output, hence the need for count() - to prevent fetching the whole dataset back to the command issuing machine (90 GB for Cord19).&lt;/p&gt;
&lt;p&gt;Overall pre-processing is a straightforward - &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform/blob/main/gears_pipeline_sentence_register.py&quot;&gt;full code&lt;/a&gt; is here.&lt;/p&gt;
&lt;p&gt;Things to keep in mind:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Node process can only save locally - we don&#39;t move data, anything you want to save should have hashtag, for example to add to the set of processed_docs:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; execute&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;SADD&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;processed_docs_{%s}&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;#39; %&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; hashtag&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;()&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;article_id&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;2&quot;&gt;
&lt;li&gt;Loading external libraries into the computational threat, for example, symspell requires additional dictionaries and needs two steps to load:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt; &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt; load symspell and relevant dictionaries&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt; &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; sym_spell&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;None&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt; def&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; load_symspell&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;  import&lt;/span&gt;&lt;span&gt; pkg_resources&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt;  from&lt;/span&gt;&lt;span&gt; symspellpy&lt;/span&gt;&lt;span style=&quot;color: #7DCFFF;&quot;&gt; import&lt;/span&gt;&lt;span&gt; SymSpell&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span&gt; Verbosity&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  sym_spell&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt; SymSpell&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt;max_dictionary_edit_distance&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; prefix_length&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  dictionary_path&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; pkg_resources&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;resource_filename&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;symspellpy&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;frequency_dictionary_en_82_765.txt&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  bigram_path&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt; =&lt;/span&gt;&lt;span&gt; pkg_resources&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;resource_filename&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;      &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;symspellpy&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ECE6A;&quot;&gt;frequency_bigramdictionary_en_243_342.txt&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;  # term_index is the column of the term and count_index is the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #51597D;font-style: italic;&quot;&gt;  # column of the term frequency&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  sym_spell&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;load_dictionary&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;dictionary_path&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; term_index&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; count_index&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  sym_spell&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #7AA2F7;&quot;&gt;load_bigram_dictionary&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #C0CAF5;&quot;&gt;bigram_path&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; term_index&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #E0AF68;&quot;&gt; count_index&lt;/span&gt;&lt;span style=&quot;color: #89DDFF;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #FF9E64;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #9ABDF5;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #BB9AF7;&quot;&gt;  return&lt;/span&gt;&lt;span&gt; sym_spell&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;ol start=&quot;3&quot;&gt;
&lt;li&gt;Scispacy is a great library and data science tool, but after a few iterations with deploying it I ended up reading data model documentation for UMLS Methathesaurus and decided to build Aho-Corasick automata directly from UMLS data. (MRXW_ENG.RRF contains all terms form for English mapped to CUI). Aho-Corasick allowed me to match incoming sentences into pairs of nodes (concepts from the medical dictionary) and present sentences as edges in a graph, Gears related code is simple:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #A9B1D6; background-color: #1A1B26;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; bg = GearsBuilder(&amp;#39;KeysReader&amp;#39;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; bg.foreach(process_item)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; bg.count()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; bg.register(&amp;#39;sentence:*&amp;#39;,  mode=&amp;quot;async_local&amp;quot;,onRegistered=OnRegisteredAutomata)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;OnRegisteredAutomata will perform similarly to symspell example above except it will download pre-build Aho-Corasick automata (30Mb).
Aho-Corasick is a very fast matcher and allows to perform &amp;gt;900 Mb text per second even on commodity laptop, RedisGears cluster makes a very smooth distribution of data and ML model and matching using available CPU and Memory. Full matcher &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform/blob/main/sentences_matcher_register.py&quot;&gt;code&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Output of the matcher: nodes and edges are candidates to use another RedisGears pattern rgsync where you can write fast into Redis and RedisGears are going to replicate data into slower storage using RedisStreams.
But I decided to use streams and handcraft the population of the RedisGraph database, which will be focus of the next blog post.&lt;/p&gt;
&lt;p&gt;Output of the matcher: nodes and edges are candidates to use another RedisGears pattern &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/RedisGears/rgsync&quot;&gt;rgsync&lt;/a&gt; where you can write fast into Redis and RedisGears are going to replicate data into slower storage using RedisStreams, while this demo uses streams and populates RedisGraph database with nodes and edges calculating rank of each.&lt;/p&gt;
&lt;h2 id=&quot;call-to-action&quot;&gt;Call to action&lt;/h2&gt;
&lt;p&gt;We took OCR scans in JSON format and turned them into Knowledge Graph, demonstrating how you can traditional Semantic Network/OWL/Methathesaurus technique based on Unified Medical Language System. Redis Ecosystem offers a lot to the data science community, and can take place at the core of Kaggle notebooks, ML frameworks and make deployment and distribution of data more enjoyable. The success of our industry depends on how our tools work together — regardless of whether they are engineering, data science, machine learning and organisational or architectural.&lt;/p&gt;
&lt;p&gt;With the collaboration of RedisLabs and community, the full pipeline code is available via https://github.com/applied-knowledge-systems/the-pattern-platform. In case, you want to try it locally, then you can find a Docker Launch script in the root of the repository along with short quickstart guide. PR and suggestions are welcome. The overall goal of the project is to allow other to build their more interesting pipeline on top of it.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;http://thepattern.digital/&quot;&gt;Covid19 - Redis Knowledge Graph in 3D&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.kaggle.com/allen-institute-for-ai/CORD-19-research-challenge&quot;&gt;COVID-19 Open Research Dataset Challenge (CORD-19)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform&quot;&gt;Source Code for NLP pipeline based on RedisGears &lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
      </item>
      <item>
          <title>Metadata Management</title>
          <pubDate>Sat, 14 May 2022 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/metadata/</link>
          <guid>https://reference-architecture.ai/docs/metadata/</guid>
          <description xml:base="https://reference-architecture.ai/docs/metadata/">&lt;p&gt;In CORD 19 dataset mentioned in &lt;a href=&quot;https://reference-architecture.ai/docs/intake/&quot;&gt;Data Acquisition&lt;/a&gt; Metadata stored in the separate csv file from the source data. &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform/blob/2168aa194cc9d84457e3faac0299939e307900ae/parse_publish_dates_threaded.py&quot;&gt;Here&lt;/a&gt; simple script to parse date/times and attach it to JSON/XML files&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Contribution Guidelines</title>
          <pubDate>Wed, 15 Dec 2021 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/contribution/</link>
          <guid>https://reference-architecture.ai/docs/contribution/</guid>
          <description xml:base="https://reference-architecture.ai/docs/contribution/">&lt;p&gt;General guidelines for contributing to the project.&lt;/p&gt;</description>
      </item>
      <item>
          <title>The Pattern: Machine Learning Natural Language Processing meets VR/AR</title>
          <pubDate>Mon, 31 Aug 2020 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/ai-product/</link>
          <guid>https://reference-architecture.ai/docs/ai-product/</guid>
          <description xml:base="https://reference-architecture.ai/docs/ai-product/">&lt;p&gt;To fight ever-increasing complexity, &quot;The Pattern&quot; projects help find relevant knowledge using Artificial Intelligence and novel UX elements, all powered by Redis - a new generation real-time data fabric turned into knowledge fabric&lt;/p&gt;
&lt;p&gt;Overall repository for CORD19 medical NLP pipeline, API and UI, design and architecture.&lt;/p&gt;
&lt;p&gt;Demo Video:&lt;/p&gt;
&lt;div class=&quot;video-embed&quot;&gt;
  &lt;iframe src=&quot;https://www.youtube-nocookie.com/embed/zCqzB0YVgA0&quot; title=&quot;Embedded video&quot;
    loading=&quot;lazy&quot; frameborder=&quot;0&quot; referrerpolicy=&quot;strict-origin-when-cross-origin&quot;
    allow=&quot;accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture&quot;
    allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;p&gt;Demo Server (no persistance): &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://thepattern.digital/&quot;&gt;https://thepattern.digital/&lt;/a&gt;&lt;/p&gt;
&lt;h1 id=&quot;the-challenge&quot;&gt;The challenge&lt;/h1&gt;
&lt;p&gt;The medical profession put a lot of effort into collaboration, starting from Latin as a common language to industry-wide thesauruses like &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.nlm.nih.gov/research/umls/index.html&quot;&gt;UMLS&lt;/a&gt;. However, if full of scandals where publications in a prestigious journal would be retracted, and the World Health Organisation would change its policy advice based on the article. I think &quot;paper claiming that eating a bat-like Pokémon sparked the spread of COVID-19&quot; takes a prize. One would say that editors in those journals don&#39;t do their job, and while it may seem true, I would say they had no chance: with a number of publications about COVID (SARS-V) passing 300+ per day, we need better tools to navigate via such flow of information.
When exploring science or engineering topics, I look at the diversity of the opinion, not the variety of the same cluster of words or the same thought. I want to avoid confirmation bias. I want to find articles relevant to the same concept, not necessarily the ones which have similar words. My focus is to build a natural language processing pipeline capable of handling a large number of documents and concepts, incorporating System 1 AI (fast, intuitive reasoning) and System 2 (high-level reasoning) and then present knowledge in a modern VR/AR visualisation. Search or rather information exploration should be spatial, preferably in VR (memory palace, see Theatre of Giulio Camillo). A force-directed graph is a path towards it, where visuals are assisted by text — relevant text pops up on the connection and where people explore the concepts and then dig deeper into the text. The purpose of the pipeline is that knowledge should be reusable and shareable.&lt;/p&gt;
&lt;h1 id=&quot;community&quot;&gt;Community&lt;/h1&gt;
&lt;p&gt;Join our community on &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://discord.gg/rdgsCuJ4P4&quot;&gt;Discord&lt;/a&gt; or post on &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern/discussions&quot;&gt;GitHub Discussions&lt;/a&gt;](https://github.com/applied-knowledge-systems/the-pattern/discussions)&lt;/p&gt;
</description>
      </item>
      <item>
          <title>Data Acquisition</title>
          <pubDate>Mon, 31 Aug 2020 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://reference-architecture.ai/docs/intake/</link>
          <guid>https://reference-architecture.ai/docs/intake/</guid>
          <description xml:base="https://reference-architecture.ai/docs/intake/">&lt;p&gt;For the Reference Architecture for AI, we used Kaggle &lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://www.kaggle.com/datasets/allen-institute-for-ai/CORD-19-research-challenge&quot;&gt;Cord19 dataset&lt;/a&gt;, &quot;COVID-19 Open Research Dataset (CORD-19). CORD-19 is a resource of over 1,000,000 scholarly articles, including over 400,000 with full text, about COVID-19, SARS-CoV-2, and related coronaviruses. This freely available dataset is provided to the global research community to apply recent advances in natural language processing and other AI techniques to generate new insights in support of the ongoing fight against this infectious disease.&quot;&lt;/p&gt;
&lt;h1 id=&quot;ingest-documents&quot;&gt;Ingest documents&lt;/h1&gt;
&lt;p&gt;&lt;a rel=&quot;noopener nofollow noreferrer external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/applied-knowledge-systems/the-pattern-platform/blob/6fe80e7bf6c8c3baf2d1bd6aa300ff1ef336d523/RedisIntakeRedisClusterSample.py&quot;&gt;Example script&lt;/a&gt; parses documents taking out body_text and saves under paragraphs in Redis cluster.&lt;/p&gt;
</description>
      </item>
    </channel>
</rss>
