Jika Anda memerlukan info lebih lanjut, bantuan, atau ingin memberikan masukan umum tentang Orama, bergabunglah dengan saluran Orama Slack
Anda dapat menginstal Orama menggunakan npm
, yarn
, pnpm
, bun
:
npm i @orama/orama
Atau impor langsung ke modul browser:
< html >
< body >
< script type =" module " >
import { create , insert , search } from 'https://cdn.jsdelivr.net/npm/@orama/orama@latest/+esm'
</ script >
</ body >
</ html >
Dengan Deno, Anda cukup menggunakan URL CDN yang sama atau menggunakan penentu npm:
import { create , search , insert } from 'npm:@orama/orama'
Baca dokumentasi lengkapnya di https://docs.orama.com.
Orama cukup mudah digunakan. Hal pertama yang harus dilakukan adalah membuat instance database baru dan menetapkan skema pengindeksan:
import { create , insert , remove , search , searchVector } from '@orama/orama'
const db = create ( {
schema : {
name : 'string' ,
description : 'string' ,
price : 'number' ,
embedding : 'vector[1536]' , // Vector size must be expressed during schema initialization
meta : {
rating : 'number' ,
} ,
} ,
} )
insert ( db , {
name : 'Noise cancelling headphones' ,
description : 'Best noise cancelling headphones on the market' ,
price : 99.99 ,
embedding : [ 0.2432 , 0.9431 , 0.5322 , 0.4234 , ... ] ,
meta : {
rating : 4.5
}
} )
const results = search ( db , {
term : 'Best headphones'
} )
// {
// elapsed: {
// raw: 21492,
// formatted: '21μs',
// },
// hits: [
// {
// id: '41013877-56',
// score: 0.925085832971998432,
// document: {
// name: 'Noise cancelling headphones',
// description: 'Best noise cancelling headphones on the market',
// price: 99.99,
// embedding: [0.2432, 0.9431, 0.5322, 0.4234, ...],
// meta: {
// rating: 4.5
// }
// }
// }
// ],
// count: 1
// }
Orama saat ini mendukung 10 tipe data berbeda:
Jenis | Keterangan | Contoh |
---|---|---|
string | Serangkaian karakter. | 'Hello world' |
number | Nilai numerik, baik float atau integer. | 42 |
boolean | Nilai boolean. | true |
enum | Nilai enum. | 'drama' |
geopoint | Nilai titik geografis. | { lat: 40.7128, lon: 74.0060 } |
string[] | Serangkaian string. | ['red', 'green', 'blue'] |
number[] | Serangkaian angka. | [42, 91, 28.5] |
boolean[] | Array boolean. | [true, false, false] |
enum[] | Serangkaian enum. | ['comedy', 'action', 'romance'] |
vector[<size>] | Vektor angka untuk melakukan pencarian vektor. | [0.403, 0.192, 0.830] |
Orama mendukung pencarian vektor dan hybrid hanya dengan mengatur mode: 'vector'
saat melakukan pencarian.
Untuk melakukan penelusuran semacam ini, Anda harus menyediakan penyematan teks pada waktu penelusuran:
import { create , insertMultiple , search } from '@orama/orama'
const db = create ( {
schema : {
title : 'string' ,
embedding : 'vector[5]' ' , // we are using a 5-dimensional vector.
} ,
} ) ;
insertMultiple ( db , [
{ title : 'The Prestige' , embedding : [ 0.938293 , 0.284951 , 0.348264 , 0.948276 , 0.56472 ] } ,
{ title : 'Barbie' , embedding : [ 0.192839 , 0.028471 , 0.284738 , 0.937463 , 0.092827 ] } ,
{ title : 'Oppenheimer' , embedding : [ 0.827391 , 0.927381 , 0.001982 , 0.983821 , 0.294841 ] } ,
] )
const results = search ( db , {
// Search mode. Can be 'vector', 'hybrid', or 'fulltext'
mode : 'vector' ,
vector : {
// The vector (text embedding) to use for search
value : [ 0.938292 , 0.284961 , 0.248264 , 0.748276 , 0.26472 ] ,
// The schema property where Orama should compare embeddings
property : 'embedding' ,
} ,
// Minimum similarity to determine a match. Defaults to `0.8`
similarity : 0.85 ,
// Defaults to `false`. Setting to 'true' will return the embeddings in the response (which can be very large).
includeVectors : true ,
} )
Mengalami kesulitan dalam membuat penyematan untuk penelusuran vektor dan hibrid? Coba plugin @orama/plugin-embeddings
kami!
import { create } from '@orama/orama'
import { pluginEmbeddings } from '@orama/plugin-embeddings'
import '@tensorflow/tfjs-node' // Or any other appropriate TensorflowJS backend, like @tensorflow/tfjs-backend-webgl
const plugin = await pluginEmbeddings ( {
embeddings : {
// Schema property used to store generated embeddings
defaultProperty : 'embeddings' ,
onInsert : {
// Generate embeddings at insert-time
generate : true ,
// properties to use for generating embeddings at insert time.
// Will be concatenated to generate a unique embedding.
properties : [ 'description' ] ,
verbose : true ,
}
}
} )
const db = create ( {
schema : {
description : 'string' ,
// Orama generates 512-dimensions vectors.
// When using @orama/plugin-embeddings, set the property where you want to store embeddings as `vector[512]`.
embeddings : 'vector[512]'
} ,
plugins : [ plugin ]
} )
// Orama will generate and store embeddings at insert-time!
await insert ( db , { description : 'Classroom Headphones Bulk 5 Pack, Student On Ear Color Varieties' } )
await insert ( db , { description : 'Kids Wired Headphones for School Students K-12' } )
await insert ( db , { description : 'Kids Headphones Bulk 5-Pack for K-12 School' } )
await insert ( db , { description : 'Bose QuietComfort Bluetooth Headphones' } )
// Orama will also generate and use embeddings at search time when search mode is set to "vector" or "hybrid"!
const searchResults = await search ( db , {
term : 'Headphones for 12th grade students' ,
mode : 'vector'
} )
Ingin menggunakan model penyematan OpenAI? Gunakan plugin Proksi Aman kami untuk memanggil OpenAI dari sisi klien dengan aman.
Sejak v3.0.0
, Orama memungkinkan Anda membuat pengalaman seperti ChatGPT/Perplexity/SearchGPT Anda sendiri. Anda perlu memanggil API OpenAI, jadi kami sangat menyarankan penggunaan Plugin Proksi Aman untuk melakukannya dengan aman dari sisi klien Anda. Gratis!
import { create , insert } from '@orama/orama'
import { pluginSecureProxy } from '@orama/plugin-secure-proxy'
const secureProxy = await pluginSecureProxy ( {
apiKey : 'my-api-key' ,
defaultProperty : 'embeddings' ,
models : {
// The chat model to use to generate the chat answer
chat : 'openai/gpt-4o-mini'
}
} )
const db = create ( {
schema : {
name : 'string'
} ,
plugins : [ secureProxy ]
} )
insert ( db , { name : 'John Doe' } )
insert ( db , { name : 'Jane Doe' } )
const session = new AnswerSession ( db , {
// Customize the prompt for the system
systemPrompt : 'You will get a name as context, please provide a greeting message' ,
events : {
// Log all state changes. Useful to reactively update a UI on a new message chunk, sources, etc.
onStateChange : console . log ,
}
} )
const response = await session . ask ( {
term : 'john'
} )
console . log ( response ) // Hello, John Doe! How are you doing?
Baca dokumentasi lengkapnya di sini.
Baca dokumentasi lengkapnya di https://docs.orama.com/open-source.
Tulis plugin Anda sendiri: https://docs.orama.com/open-source/plugins/writing-your-own-plugins
Orama dilisensikan di bawah lisensi Apache 2.0.