WICG / proposals

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

window.ai.rag #158

Open hemanth opened 2 weeks ago

hemanth commented 2 weeks 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 2 weeks 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 2 weeks 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?