WICG / proposals

A home for well-formed proposed incubations for the web platform. All proposals welcome.
https://wicg.io/
Other
233 stars 16 forks source link

window.ai.rag #158

Open hemanth opened 4 months ago

hemanth commented 4 months ago

The window.ai.rag API enables web applications to perform Retrieval-Augmented Generation (RAG) directly in the browser. RAG combines the power of large language models with the ability to retrieve and incorporate relevant information from a knowledge base.

This API is particularly useful for:

  1. Question-answering systems that need access to up-to-date or specialized information
  2. Content generation tools that require factual accuracy and domain-specific knowledge
  3. Chatbots or virtual assistants that need to provide informative responses based on a specific corpus of data

By implementing RAG in the browser, applications can:

  1. Provide more accurate and contextually relevant responses
  2. Reduce the load on server-side infrastructure
  3. Offer personalized experiences based on user-specific data

More use-cases:

  1. Information Retrieval and Synthesis
  2. Personalized Content Generation
  3. Knowledge Management and Curation
  4. Contextual Assistance
  5. Decision Support Systems
  6. Creative Augmentation
  7. Real-time Information Processing
  8. Predictive Analytics
  9. Interactive Learning and Training
  10. Data Validation and Enrichment
  11. Augmented Communication
  12. Semantic Analysis and Understanding

API:

interface RAGOptions {
  model: string; // Identifier for the base language model
  knowledgeBase: KnowledgeBase;
  retrievalOptions?: RetrievalOptions;
  generationOptions?: GenerationOptions;
}

interface KnowledgeBase {
  type: 'vector' | 'inverted-index' | 'hybrid';
  data: ArrayBuffer | string[]; // Depending on the type
}

interface RetrievalOptions {
  topK?: number; // Number of documents to retrieve
  similarityThreshold?: number;
}

interface GenerationOptions {
  maxTokens?: number;
  temperature?: number;
}

interface RAGResult {
  generatedText: string;
  retrievedDocuments: string[];
  confidence: number;
}

interface WindowAI {
  rag: {
    query(input: string, options: RAGOptions): Promise<RAGResult>;
    updateKnowledgeBase(newData: ArrayBuffer | string[]): Promise<void>;
  };
}

interface Window {
  ai: WindowAI;
}
const result = await window.ai.rag.query(question, ragOptions);
yoavweiss commented 4 months ago

Hey @hemanth!! I think it might be good to have a single proposal for the various related LLM things. It might also be best to start with a focus on the use cases you're setting out to solve, rather than specific API shapes.

hemanth commented 4 months ago

Hello @yoavweiss I briefly touched upon the use-cases, update them with more.

The window.ai.rag would essentially implement a generic RAG (Retrieval-Augmented Generation) function that takes an input and retrieves a set of relevant or supporting documents based on a given source.

single proposal for the various related LLM things

I would love too, you suggest we combine all of #160 #159 #158 into a single proposal?

petamoriken commented 3 months ago

IMHO, .ai namespace is better in navigator than window. According to the TAG review, the Web Translation API should not be part of the .ai namespace (https://github.com/w3ctag/design-reviews/issues/948#issuecomment-2274380634), so it could still be changed to navigator. How about that?

hemanth commented 3 months ago

Name spaces should be function-led rather than technology-used-to-deliver-the-function-led.

The use of a .ai namespace is intentional, reflecting the API's focus on AI technology. This explicit naming clarifies its purpose and capabilities, distinguishing it from traditional services in a multi-functional environment. Additionally, the .ai namespace is gaining recognition as the standard for AI-related technologies, enhancing clarity for end users.

Would you be suggesting the use of window.navigator.ai?

I would appreciate your insights on any potential side effects of utilizing the .ai namespace on window.