Skip to content

Commit

Permalink
Working Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
awhiteside1 committed Sep 16, 2024
1 parent 7b0de08 commit fa3467b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 22 deletions.
1 change: 0 additions & 1 deletion packages/semantic-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"postinstall": "pnpm build:stub"
},
"devDependencies": {

"@payloadcms/db-mongodb": "^3.0.0-beta.107",
"@payloadcms/db-postgres": "^3.0.0-beta.107",
"dockerode": "^4.0.2",
Expand Down
11 changes: 5 additions & 6 deletions packages/semantic-search/src/components/lancedb/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {connect, type Table} from '@lancedb/lancedb'
import {getRegistry, LanceSchema} from '@lancedb/lancedb/embedding'
import {Utf8} from 'apache-arrow'
import type {Identifier, InsertFields, VectorDB} from '../../types'
import {OllamaEmbeddings, register} from '../ollama'
import { type Table, connect } from '@lancedb/lancedb'
import { LanceSchema, getRegistry } from '@lancedb/lancedb/embedding'
import { Utf8 } from 'apache-arrow'
import type { Identifier, InsertFields, VectorDB } from '../../types'
import { OllamaEmbeddings, register } from '../ollama'

register()

Expand All @@ -25,7 +25,6 @@ export class LanceDB implements VectorDB {
}

static async create(path = './lancedb') {

const func = new OllamaEmbeddings({
host: 'http://100.67.29.127:11434',
model: 'nomic-embed-text',
Expand Down
6 changes: 3 additions & 3 deletions packages/semantic-search/src/components/ollama/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getRegistry, TextEmbeddingFunction,} from '@lancedb/lancedb/embedding'
import type {Float} from 'apache-arrow'
import {Ollama} from 'ollama'
import { TextEmbeddingFunction, getRegistry } from '@lancedb/lancedb/embedding'
import type { Float } from 'apache-arrow'
import { Ollama } from 'ollama'

interface Options {
model: string
Expand Down
6 changes: 3 additions & 3 deletions packages/semantic-search/src/hooks/afterChangeHook.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {FieldHook, FieldHookArgs} from 'payload'
import {isObject, isString} from 'radash'
import {getSemanticSearchCustom} from '../utils/customContext'
import type { FieldHook, FieldHookArgs } from 'payload'
import { isObject, isString } from 'radash'
import { getSemanticSearchCustom } from '../utils/customContext'

export const afterChangeHook: FieldHook = (args) => {
if (args.operation === 'create' || args.operation === 'update') {
Expand Down
10 changes: 5 additions & 5 deletions packages/semantic-search/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import defu from 'defu'
import type {Config, FieldBase} from 'payload'
import {afterChangeHook} from './hooks/afterChangeHook'
import type {SemanticSearchPluginConfig} from './types'
import {setupSemanticSearchCustom} from './utils/customContext'
import {getField, parseFields} from './utils/fields'
import type { Config, FieldBase } from 'payload'
import { afterChangeHook } from './hooks/afterChangeHook'
import type { SemanticSearchPluginConfig } from './types'
import { setupSemanticSearchCustom } from './utils/customContext'
import { getField, parseFields } from './utils/fields'

export const semanticSearchPlugin =
(incomingPluginConfig: SemanticSearchPluginConfig) =>
Expand Down
6 changes: 3 additions & 3 deletions packages/semantic-search/src/utils/customContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Config} from 'payload'
import {isObject} from 'radash'
import type {VectorDB} from '../types'
import type { Config } from 'payload'
import { isObject } from 'radash'
import type { VectorDB } from '../types'

export type SemanticSearchCustomObject = {
vectorDB: VectorDB
Expand Down
7 changes: 6 additions & 1 deletion packages/semantic-search/src/utils/fields.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type {CollectionConfig, Config, TextareaField, TextField,} from 'payload'
import type {
CollectionConfig,
Config,
TextField,
TextareaField,
} from 'payload'

export interface FieldEntry {
collectionConfig: CollectionConfig
Expand Down

0 comments on commit fa3467b

Please sign in to comment.