Santiago Gonzalez Toral
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- type: slide title: RaidGuild x Gaia - RAG API Pipeline Demo tags: RAG, LLMs, , data-pipeline slideOptions: keyboard: true progress: true slideNumber: true showNotes: false transition: 'fade' theme: 'night' --- ![image](https://hackmd.io/_uploads/SJUu4tEnC.png =300x) ![image](https://hackmd.io/_uploads/SJE51KN2A.png =100x) # Gaia x RaiGuild ### RAG API Pipeline #### Demo Day --- # Agenda 1. Architecture Overview 2. Defining an API Pipeline Manifest 3. rag-api-pipeline - CLI Walkthrough 4. Demo - Boardroom API 5. Issues Found and TODOs 6. Next steps --- ## Architecture Overview ![image](https://hackmd.io/_uploads/SyN54cV20.png) ---- ## Tech stack - PyAirbyte - Utilities for using Airbyte connectors in Python - Declarative API Connectors using Airbyte CDK for low-code connector development - Pathway - Python data processing framework for creating AI pipelines over data streams - Rust engine with multithreading and multiprocessing ---- ## Tech stack - Data caching at each stage of the pipeline - Airbyte DuckDB Cache for API data extraction - JSONL output connectors after normalization & chunking stages ---- ## Tech stack - Unstructured - simplify the ingestion and pre-processing of diverse data formats on data workflows for LLM - library includes functions to partition, chunk, clean, and stage raw source documents. - Gaia node for Feature Embedding generation - RAG API Server with OpenAI-like API ---- ## Tech stack - QdrantDB - vector similarity search engine and vector database - knowledge base snaphosts --- ## Defining an API Pipeline Manifest ![image](https://hackmd.io/_uploads/HJOe2543A.png) ---- ## API Spec ![image](https://hackmd.io/_uploads/BJrNF94hC.png) ---- ## Base Data retriever - Requester - Authentication - OAuth | ApiKeyAuthenticator | BearerAuthenticator | BasicHttpAuthenticator" - Paginator - NoPagination | CursorPagination | OffsetIncrement | PageIncrement - Record selector ---- ## Base Data retriever ![image](https://hackmd.io/_uploads/ByG_FqEnR.png) ---- ## Base Response Schemas ![image](https://hackmd.io/_uploads/SyJC9942R.png) ---- ## Endpoint streams definition ![image](https://hackmd.io/_uploads/SkRxo9Vh0.png) ---- ## Fields for text preprocessing ![image](https://hackmd.io/_uploads/S1aIj9N2C.png =500x) #### **Other fields will be added as metadata ---- ## Chunking parameters ![image](https://hackmd.io/_uploads/B1yH3cV3A.png) --- ## rag-api-pipeline - CLI Walkthrough ![image](https://hackmd.io/_uploads/ByoYn942R.png) --- ## Demo - Boardroom API - Aave data sample - Recent Discourse posts and proposals - [Public Gaia node with knowledge base](https://www.gaianet.ai/chat?subdomain=0x4bb75434096b3d087852c033c7714c02d3ab74dd.us.gaianet.network) ---- ### rag-api-pipeline run-all ![image](https://hackmd.io/_uploads/ryHfGiVhR.png) - `--full-refresh` option ---- ### Input API manifest ```yaml version: "3.0.0" api_name: "boardroom_api" api_parameters: cname: "aave" protocol: "aave" spec: type: Spec documentation_url: https://docs.airbyte.com/integrations/sources/boardroom connection_specification: $schema: http://json-schema.org/draft-07/schema# title: Boardroom API Spec type: object required: - api_key - cname - protocol additionalProperties: true properties: # 'TODO: This schema defines the configuration required for the source. This usually involves metadata such as database and/or authentication information.': api_key: type: string description: >- Boardroom API Key. See <a href="https://docs.boardroom.io/docs/api/05c1fb6d88a07-governance-api">here</a> for details. airbyte-secret: true cname: type: string description: >- Protocol ID a.k.a cname examples: - aave - hopprotocol protocol: type: string description: >- Alias for cname. Needed as there are a few endpoints that use `protocol` as parameter id examples: - aave - metacartel definitions: selector: type: RecordSelector extractor: type: DpathExtractor field_path: [] requester_base: type: HttpRequester url_base: "https://api.boardroom.info/v1" http_method: "GET" authenticator: type: ApiKeyAuthenticator api_token: "{{ config['api_key'] }}" inject_into: type: RequestOption field_name: "key" inject_into: request_parameter retriever_base: type: SimpleRetriever record_selector: $ref: "#/definitions/selector" paginator: type: DefaultPaginator pagination_strategy: type: CursorPagination cursor_value: "{{ response.get('nextCursor', '') }}" stop_condition: "{{ 'nextCursor' not in response }}" page_token_option: type: RequestOption field_name: "cursor" inject_into: "request_parameter" schemas: boardroom_api: type: object $schema: http://json-schema.org/draft-07/schema# properties: data: type: array nextCursor: type: - string - "null" boardroom_api_protocol: type: object $schema: http://json-schema.org/draft-07/schema# properties: data: type: object nextCursor: type: - "null" api_config: request_method: "get" content_type: "application/json" response_entrypoint_field: "data" response_primary_key: "nextCursor" endpoints: /discourseTopics: id: "discourseTopics" responseSchema: "#/schemas/boardroom_api" textSchema: $ref: "#/textSchemas/DiscourseTopic" /discourseCategories: id: "discourseCategories" responseSchema: "#/schemas/boardroom_api" textSchema: $ref: "#/textSchemas/DiscourseCategory" /discourseTopicPosts: id: "discourseTopicPosts" responseSchema: "#/schemas/boardroom_api" textSchema: $ref: "#/textSchemas/DiscourseTopicPost" "/protocols/{cname}": id: "protocol" responseSchema: "#/schemas/boardroom_api_protocol" textSchema: $ref: "#/textSchemas/Protocol" "/protocols/{cname}/proposals": id: "proposals" responseSchema: "#/schemas/boardroom_api" textSchema: $ref: "#/textSchemas/Proposal" textSchemas: Protocol: type: object properties: - cname: type: string - name: type: string - categories: type: array items: type: string Proposal: type: object properties: - title: type: string - content: type: string - summary: type: string DiscourseTopic: type: object properties: - title: type: string DiscourseCategory: type: object properties: - name: type: string - description: type: string DiscourseTopicPost: type: object properties: - body: type: string chunking_param: mode: "elements" chunking_strategy: "by_title" include_orig_elements: true max_characters: 1500 new_after_n_chars: 1024 overlap: 0 overlap_all: false combine_text_under_n_chars: 0 multipage_sections: true ``` ---- ### Generated Source Connector ```yaml check: stream_names: - discourseTopics - discourseCategories - discourseTopicPosts - protocol - proposals type: CheckStream definitions: discourseCategories_stream: $parameters: name: discourseCategories path: '"/discourseCategories"' primary_key: nextCursor retriever: $ref: '#/definitions/retriever_base' paginator: $ref: '#/definitions/paginator' requester: $ref: '#/definitions/requester_base' request_parameters: protocol: '{{ config[''protocol''] }}' schema_loader: schema: $ref: '#/schemas/boardroom_api' type: InlineSchemaLoader type: DeclarativeStream discourseTopicPosts_stream: $parameters: name: discourseTopicPosts path: '"/discourseTopicPosts"' primary_key: nextCursor retriever: $ref: '#/definitions/retriever_base' paginator: $ref: '#/definitions/paginator' requester: $ref: '#/definitions/requester_base' request_parameters: protocol: '{{ config[''protocol''] }}' schema_loader: schema: $ref: '#/schemas/boardroom_api' type: InlineSchemaLoader type: DeclarativeStream discourseTopics_stream: $parameters: name: discourseTopics path: '"/discourseTopics"' primary_key: nextCursor retriever: $ref: '#/definitions/retriever_base' paginator: $ref: '#/definitions/paginator' requester: $ref: '#/definitions/requester_base' request_parameters: protocol: '{{ config[''protocol''] }}' schema_loader: schema: $ref: '#/schemas/boardroom_api' type: InlineSchemaLoader type: DeclarativeStream paginator: page_token_option: field_name: cursor inject_into: request_parameter type: RequestOption pagination_strategy: cursor_value: '{{ response.get(''nextCursor'', '''') }}' stop_condition: '{{ ''nextCursor'' not in response }}' type: CursorPagination type: DefaultPaginator proposals_stream: $parameters: name: proposals path: '"/protocols/{{ config[''cname''] }}/proposals"' primary_key: nextCursor retriever: $ref: '#/definitions/retriever_base' paginator: $ref: '#/definitions/paginator' requester: $ref: '#/definitions/requester_base' schema_loader: schema: $ref: '#/schemas/boardroom_api' type: InlineSchemaLoader type: DeclarativeStream protocol_stream: $parameters: name: protocol path: '"/protocols/{{ config[''cname''] }}"' primary_key: nextCursor retriever: $ref: '#/definitions/retriever_base' paginator: type: NoPagination requester: $ref: '#/definitions/requester_base' schema_loader: schema: $ref: '#/schemas/boardroom_api_protocol' type: InlineSchemaLoader type: DeclarativeStream requester_base: authenticator: api_token: '{{ config[''api_key''] }}' inject_into: field_name: key inject_into: request_parameter type: RequestOption type: ApiKeyAuthenticator http_method: GET type: HttpRequester url_base: https://api.boardroom.info/v1 retriever_base: record_selector: $ref: '#/definitions/selector' type: SimpleRetriever selector: extractor: field_path: [] type: DpathExtractor type: RecordSelector schemas: boardroom_api: $schema: http://json-schema.org/draft-07/schema# properties: data: type: array nextCursor: type: - string - 'null' type: object boardroom_api_protocol: $schema: http://json-schema.org/draft-07/schema# properties: data: type: object nextCursor: type: - 'null' type: object spec: connection_specification: $schema: http://json-schema.org/draft-07/schema# additionalProperties: true properties: api_key: airbyte-secret: true description: Boardroom API Key. See <a href="https://docs.boardroom.io/docs/api/05c1fb6d88a07-governance-api">here</a> for details. type: string cname: description: Protocol ID a.k.a cname examples: - aave - hopprotocol type: string protocol: description: Alias for cname. Needed as there are a few endpoints that use `protocol` as parameter id examples: - aave - metacartel type: string required: - api_key - cname - protocol title: Boardroom API Spec type: object documentation_url: https://docs.airbyte.com/integrations/sources/boardroom type: Spec streams: - '#/definitions/discourseTopics_stream' - '#/definitions/discourseCategories_stream' - '#/definitions/discourseTopicPosts_stream' - '#/definitions/protocol_stream' - '#/definitions/proposals_stream' version: 3.0.0 ``` ---- ### rag-api-pipeline from-normalized - `--normalized-data-file` argument Let's jumpt to the terminal ---- ### Question about Disourse Post - [Link to post](https://boardroom.io/aave/discussions/18793) ![image](https://hackmd.io/_uploads/S17WA5NnC.png =400x) ![image](https://hackmd.io/_uploads/H1Ob09N2C.png =400x) ---- ### Question about Proposal - [Link to proposal](https://boardroom.io/aave/proposal/cHJvcG9zYWw6YWF2ZTpzbmFwc2hvdDoweDA0NDQ3NzExNGM2M2I1YzEzM2FkMmFhNjczYjgyNTZmYzc5OWI1YjExNjlhYzRiOTExOTYyNmFkYWRkNjUwNWY=) ![image](https://hackmd.io/_uploads/S1pIA9E30.png =400x) ---- ### Question about Proposal Results ![image](https://hackmd.io/_uploads/H1Le1jEnR.png) --- ## Results from AAVE data from Boardroom API - Endpoints: - discourseTopics: 211 - discourseCategories: 7 - discourseTopicPosts: 15085 - protocol: 1 - proposals: 1264 - Normalized recods: 16568 ~ 6 minutes - Chunked data records: 152198 ~ 14 minutes - Embeddings: N/A --- ## Issues Found and TODOs - Gaia node crashes when handling considerable load to its embeddings endpoint. - Crashed 4 public nodes (sorry) - Local nodes running on a Macbook PRO Intel/M1 ---- ### Gaia node config ```jsonl { "address": "0x198d8dec810883422c5cb417fb70db55ee3a4001", "chat": "https://huggingface.co/gaianet/Phi-3-mini-4k-instruct-GGUF/resolve/main/Phi-3-mini-4k-instruct-Q5_K_M.gguf", "chat_batch_size": "16", "chat_ctx_size": "4096", "chat_name": "Phi-3-mini-4k-instruct", "description": "The default GaiaNet node config with a Phi-3-mini-4k model and a Paris tour guide knowledge base.", "domain": "us.gaianet.network", "embedding": "https://huggingface.co/gaianet/Nomic-embed-text-v1.5-Embedding-GGUF/resolve/main/nomic-embed-text-v1.5.f16.gguf", "embedding_batch_size": "2048", "embedding_collection_name": "boardroom_api_collection", "embedding_ctx_size": "2048", "embedding_name": "Nomic-embed-text-v1.5", "llamaedge_port": "8080", "prompt_template": "phi-3-chat", "qdrant_limit": "1", "qdrant_score_threshold": "0.5", "rag_policy": "system-message", "rag_prompt": "Use the following pieces of context to answer the user's question. Respond directly to the user with your answer, do not say 'this is the answer' or 'this is the answer' or similar language. Never mention your knowledge base or say 'according to the context' or 'hypothetical' or other similar language. Use json metadata included in knowledge base whenever possible enrich your answers. The term aave refers the DAO protocol where discussions and proposals are posted. If you don't know the answer, don't try to make up an answer. \n----------------\n", "reverse_prompt": "", "snapshot": "boardroom_api_collection-3656816618511259-2024-09-03-04-54-33.snapshot.tar.gz", "system_prompt": "You are an AI assistant designed to provide clear, concise, and accurate answers to user queries. Your primary functions include retrieving relevant information from the provided RAG (Retrieval-Augmented Generation) data and utilizing your pre-training data when necessary. Use json metadata included in RAG data whenever possible enrich your answers. The term aave refers the DAO protocol where discussions and proposals are posted. If no relevant information is found, you will inform the user that you are not familiar with the knowledge." } ``` ``` wasmedge --dir .:./dashboard --env NODE_VERSION=0.3.2 --nn-preload default:GGML:AUTO:Phi-3-mini-4k-instruct-Q5_K_M.gguf --nn-preload embedding:GGML:AUTO:nomic-embed-text-v1.5.f16.gguf rag-api-server.wasm --model-name Phi-3-mini-4k-instruct,Nomic-embed-text-v1.5 --ctx-size 4096,2048 --batch-size 16,2048 --prompt-template phi-3-chat,embedding --rag-policy system-message --qdrant-collection-name boardroom_api_collection --qdrant-limit 1 --qdrant-score-threshold 0.5 --web-ui ./ --socket-addr 0.0.0.0:8080 --rag-prompt "Use the following pieces of context to answer the user's question. Respond directly to the user with your answer, do not say 'this is the answer' or 'this is the answer' or similar language. Never mention your knowledge base or say 'according to the context' or 'hypothetical' or other similar language. Use json metadata included in knowledge base whenever possible enrich your answers such as proposal voting choices and results. The term aave refers the DAO protocol where discussions and proposals are posted. If you don't know the answer, don't try to make up an answer. \n----------------\n" ``` ---- ## Issues Found and TODOs - TODOs: - E2E tests with other 4 DAOs - E2E tests with an API with a different Auth/pagination scheme - Execution plan for all other DAOs in Boardroom - Cleanup code - documentation --- ## Next steps - Have a Gaia node deployed and capable of handling enough load to its embeddings endpoint. - Complete remaining tests - Code repository with documentation ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully