Skip to main content
Follow one path to a visible result. Choose your language tab. Prerequisites:
  • Node.js 16+ or Python 3.8+
  • Valid Moss project credentials (MOSS_PROJECT_ID, MOSS_PROJECT_KEY)
  • JS: @inferedge/moss; Python: inferedge-moss

1) Install

npm install @inferedge/moss

2) Configure credentials

From the Moss portal, copy your project credentials. Set them as env vars:
export MOSS_PROJECT_ID="your_project_id"
export MOSS_PROJECT_KEY="your_project_key"

3) Create and query an index

Save and run (npx tsx quickstart.ts or python quickstart.py):
import { MossClient, DocumentInfo } from '@inferedge/moss'

const client = new MossClient(process.env.MOSS_PROJECT_ID!, process.env.MOSS_PROJECT_KEY!)

const documents: DocumentInfo[] = [
  { id: 'doc1', text: 'How do I track my order? You can track your order by logging into your account.', metadata: { category: 'shipping' } },
  { id: 'doc2', text: 'What is your return policy? We offer a 30-day return policy for most items.', metadata: { category: 'returns' } },
  { id: 'doc3', text: 'How can I change my shipping address? Contact our customer service team.', metadata: { category: 'support' } },
]

const indexName = 'faqs'
await client.createIndex(indexName, documents, 'moss-minilm') // default; use 'moss-mediumlm' for higher accuracy
await client.loadIndex(indexName)
const results = await client.query(indexName, 'How do I return a damaged product?', 3)
console.log(results.docs[0])

Example output

{
  "id": "doc2",
  "score": 0.88,
  "text": "What is your return policy? We offer a 30-day return policy for most items."
}
Need keyword-heavy results? Use alpha=0.0/alpha: 0.0 for pure keyword, alpha=1.0 for pure semantic, or a blend in between (see Retrieval for details).