-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.js
More file actions
61 lines (57 loc) · 1.58 KB
/
Copy pathsearch.js
File metadata and controls
61 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import "dotenv/config";
import { Document } from "langchain/document";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
const movies = [
{
id: 1,
title: "Stepbrother",
description: `Comedic journey full of adult humor and awkwardness.`,
},
{
id: 2,
title: "The Matrix",
description: `Deals with alternate realities and questioning what's real.`,
},
{
id: 3,
title: "Shutter Island",
description: `A mind-bending plot with twists and turns.`,
},
{
id: 4,
title: "Memento",
description: `A non-linear narrative that challenges the viewer's perception.`,
},
{
id: 5,
title: "Doctor Strange",
description: `Features alternate dimensions and reality manipulation.`,
},
{
id: 6,
title: "Paw Patrol",
description: `Children's animated movie where a group of adorable puppies save people from all sorts of emergencies.`,
},
{
id: 7,
title: "Interstellar",
description: `Features futuristic space travel with high stakes`,
},
];
const createStore = () =>
MemoryVectorStore.fromDocuments(
movies.map(
(movie) =>
new Document({
pageContent: `Title: ${movie.title}\n${movie.description}`,
metadata: { source: movie.id, title: movie.title },
})
),
new OpenAIEmbeddings()
);
export const search = async (query, count = 1) => {
const store = await createStore();
return store.similaritySearch(query, count);
};
console.log(await search("something that kids will love"));