Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 3 additions & 97 deletions app.vue
Original file line number Diff line number Diff line change
@@ -1,99 +1,5 @@
<template>
<main>
<div class="items-center justify-center flex pt-4">
<img class="w-36" src="@/public/logo.png">
</div>
<h1 class="text-4xl pt-5 font-bold text-black text-center">
Vector Search with Weaviate
</h1>

<div class="items-center pb-6 pt-10 p-8">
<h2 class="sr-only">Steps</h2>

<div class="items-center flex justify-center">
<p class="text-center text-m">
Search through what ever you want!
</p>
</div>
</div>

<div class="justify-center items-center">
<div class="flex items-center justify-center pt-3">
<label for="Search" class="sr-only"> Search </label>

<input v-model="searchTerm" type="text" id="SearchTerm" placeholder="what are you looking for?"
class="w-2/3 rounded-md border-gray-200 bg-slate-300 py-2.5 pl-4 pe-10 shadow-sm sm:text-sm placeholder:text-gray-800" />
</div>
<p class="item-center flex justify-center text-xs text-gray-600 pt-2 pb-4">
try and search for "posts on animals"
</p>

<div class="flex items-start justify-center pt-3 gap-2">

<button @click="submitSearch()"
class="inline-block rounded border border-white bg-black px-12 py-3 text-sm font-medium text-lime-500 transition hover:border-black hover:bg-lime-500 hover:text-black focus:outline-none focus:ring focus:ring-yellow-400">
Search
</button>
</div>

<div v-if="searchResult" class="flex items-start justify-center">
<div
class="item-start absolute flex z-10 mt-2 w-[750px] divide-y divide-gray-100 rounded-md border border-gray-100 bg-slate-200 shadow-lg"
role="menu">
<div class="p-2">
<strong class="block p-2 text-xs font-bold uppercase text-black">
results
</strong>
<div>
<p>
{{ searchResult}}
</p>
</div>
<!-- <div v-for="result in searchResult">
<div class="space-y-4">
<details class="group [&_summary::-webkit-details-marker]:hidden" open>
<summary
class="flex cursor-pointer items-center justify-between gap-1.5 rounded-lg text-sm p-4 text-gray-900">
<h2 class="font-medium">
{{ result.properties.title }} by {{ result.properties.artist }}
</h2>

<svg class="h-5 w-5 shrink-0 transition duration-300 group-open:-rotate-180"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
</svg>
</summary>

<p class="mt-2 px-4 text-xs leading-relaxed text-gray-700">
hi
</p>
</details>
</div>
</div> -->
</div>
</div>
</div>
<div v-if="loading" class="flex items-start justify-center">
<svg aria-hidden="true" class="w-8 h-8 my-2 text-gray-200 animate-spin fill-lime-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
</svg>
<div>
<NuxtPage />
</div>
</div>

</main>
</template>


<script setup lang="ts">
import { type TrackSearchResult} from "./types";
const searchTerm = ref('')
const loading = ref(false)

const searchResult = ref<TrackSearchResult>()

async function submitSearch() {
searchResult.value = await $fetch(`/api/newsearch?query=${searchTerm.value}`)
}

</script>
</template>
18 changes: 18 additions & 0 deletions components/cover.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<template>
<div class="items-center justify-center flex pt-4">
<img class="w-36" src="@/public/logo.png">
</div>
<h1 class="text-4xl pt-5 font-bold text-black text-center">
Vector Search with Weaviate
</h1>

<div class="items-center pb-6 pt-10 p-8">
<h2 class="sr-only">text</h2>

<div class="items-center flex justify-center">
<p class="text-center text-m">
Search through what ever you want!
</p>
</div>
</div>
</template>
13 changes: 13 additions & 0 deletions components/loading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div class="flex items-start justify-center">
<svg aria-hidden="true" class="w-8 h-8 my-2 text-gray-200 animate-spin fill-lime-600" viewBox="0 0 100 101"
fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor" />
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill" />
</svg>
</div>
</template>
32 changes: 32 additions & 0 deletions components/results.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div v-if="searchResult" class="flex items-start justify-center">
<div class="item-start absolute flex z-10 mt-2 w-[750px] divide-y divide-gray-100 rounded-md border border-gray-100 bg-slate-200 shadow-lg"
role="menu">
<div class="p-2">
<strong class="block p-2 text-xs font-bold uppercase text-black">
results
</strong>
<div>
</div>
<div v-for="item in searchResult">
<div class="space-y-4">
<details class="group [&_summary::-webkit-details-marker]:hidden" open>
<summary
class="flex cursor-pointer items-center justify-between gap-1.5 rounded-lg text-sm p-4 text-gray-900">
<h2 class="font-medium">
{{ item.properties.title }} by {{ item.properties.artist }}
</h2>
</summary>

</details>
</div>
</div>
</div>
</div>
</div>
</template>

<script setup>
const props = defineProps(['searchResult']);

</script>
26 changes: 26 additions & 0 deletions components/search.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

<template>
<div class="justify-center items-center">
<div class="flex items-center justify-center pt-3">
<label for="Search" class="sr-only"> Search </label>

<input v-model="searchTerm" type="text" id="SearchTerm" placeholder="what are you looking for?"
class="w-2/3 rounded-md border-gray-200 bg-slate-300 py-2.5 pl-4 pe-10 shadow-sm sm:text-sm placeholder:text-gray-800" />
</div>
<p class="item-center flex justify-center text-xs text-gray-600 pt-2 pb-4">
try and search for "posts on animals"
</p>

<div class="flex items-start justify-center pt-3 gap-2">
<button @click="$emit('runSearch', searchTerm)"
class="inline-block rounded border border-white bg-black px-12 py-3 text-sm font-medium text-lime-500 transition hover:border-black hover:bg-lime-500 hover:text-black focus:outline-none focus:ring focus:ring-yellow-400">
Search
</button>
</div>
</div>
</template>

<script setup>
const searchTerm = ref('')

</script>
9 changes: 9 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,14 @@ export default defineNuxtConfig({
weaviateToken: '',
openai: '',
cohere: '',
},
nitro: {
experimental: {
tasks: true
},
scheduledTasks: {
// Run `db:migrate` task every minute
'15 13 * * 1-5': ['db:migrate']
}
}
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"nuxt": "^3.11.1",
"vue": "^3.4.21",
"vue-router": "^4.3.0",
"weaviate-client": "^3.0.0-beta.22",
"weaviate-client": "^3.0.0-beta.23",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
27 changes: 27 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<main>
<Cover />
<Search @run-search="submitSearch" />
<Loading v-if="loading" />
<h1 class="text-4xl pt-5 font-bold text-black text-center">
{{ searchResult }}
</h1>
<!-- <Results :search-result="searchResult" /> -->
</main>
</template>


<script setup lang="ts">
const loading = ref(false)

const searchResult = ref()

async function submitSearch(searchTerm: string) {
searchResult.value = null
loading.value = true
searchResult.value = await $fetch(`/api/search?query=${searchTerm}`)
loading.value = false
}

</script>

40 changes: 0 additions & 40 deletions server/api/newsearch.ts

This file was deleted.

51 changes: 26 additions & 25 deletions server/api/search.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
import weaviate, { WeaviateClient } from "weaviate-client"
import { z } from 'zod'

const responseSchema = z.object({
query: z.string(),
})

export default defineEventHandler<{query: { query: string } }>(async (event) => {
const config = useRuntimeConfig(event)
export default defineLazyEventHandler(async () => {
const config = useRuntimeConfig()

const client: WeaviateClient = await weaviate.connectToWCS(
config.weaviateURL,
{
authCredentials: new weaviate.ApiKey(config.weaviateToken),
headers: {
'X-OpenAI-Api-Key': config.openai,
'X-Cohere-Api-Key': config.cohere,
}
const client: WeaviateClient = await weaviate.connectToWCS(
config.weaviateURL,
{
authCredentials: new weaviate.ApiKey(config.weaviateToken),
headers: {
'X-OpenAI-Api-Key': config.openai,
}
)
}
)

const result = await getValidatedQuery(event, body => responseSchema.safeParse(body))
if (!result.success)
throw result.error.issues
const responseSchema = z.object({
query: z.string(),
})

// User object is validated and typed!
const searchTerm = result.data.query
const myCollection = client.collections.get('TrackSearcher')
async function vectorSearch(query:string) {

}

const response = await myCollection.query.nearText(searchTerm, {
limit: 5
return defineEventHandler<{query: { query: string } }>(async (event) => {

const result = await getValidatedQuery(event, body => responseSchema.safeParse(body))
if (!result.success)
throw result.error.issues

const searchTerm = result.data.query

return searchTerm
})

return response.objects
})
})
15 changes: 8 additions & 7 deletions types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import weaviate, { type WeaviateObjectType } from 'weaviate-client'
import weaviate, { type GenerateObject, type GenerativeReturn, type WeaviateObjectType } from 'weaviate-client'

export type QuoteType = {
quote: string;
Expand All @@ -12,15 +12,16 @@ export type JeopartyCollection = {
}

export type TrackSearcher = {
title: string,
artist: string,
album: string,
year: number,
rank: number,
title: string
artist: string
album: string
rank: number
}

export type TrackSearchResult = {
response: WeaviateObjectType<TrackSearcher>
response: GenerateObject<TrackSearcher>

}

export type SearchResult = {
Expand Down
Loading