MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / predict

Method predict

packages/llm/src/langchain.ts:34–97  ·  view source on GitHub ↗
({
    query,
    typesenseApiKey,
    communityName,
    summarize,
    accountId,
    threadId,
  }: {
    query: string;
    typesenseApiKey: string;
    communityName: string;
    accountId: string;
    summarize: boolean;
    threadId: string;
  })

Source from the content-addressed store, hash-verified

32
33export default class LangChain {
34 static async predict({
35 query,
36 typesenseApiKey,
37 communityName,
38 summarize,
39 accountId,
40 threadId,
41 }: {
42 query: string;
43 typesenseApiKey: string;
44 communityName: string;
45 accountId: string;
46 summarize: boolean;
47 threadId: string;
48 }) {
49 const body = await Typesense.queryThreads({
50 query,
51 apiKey: typesenseApiKey,
52 });
53
54 if (summarize) {
55 for await (let item of body) {
56 item.body = await this.summarize(item.body);
57 }
58 }
59 const typesenseResults = body
60 .filter((t) => t.id !== threadId)
61 .map(
62 (b) =>
63 new Document({
64 pageContent: b.body,
65 metadata: { source: b.id },
66 })
67 );
68
69 const directory = `.db/${communityName}`;
70 const fileStore = await FaissStore.load(directory, embeddingsModel);
71 const fileResults = await fileStore.similaritySearch(query, env.CHUNKS);
72
73 const prismaVectorStore = PrismaVectorStore.withModel<database.embeddings>(
74 database.prisma
75 ).create(embeddingsModel, {
76 prisma: database.Prisma,
77 tableName: 'embeddings',
78 vectorColumnName: 'embedding',
79 columns: {
80 threadId: PrismaVectorStore.IdColumn,
81 value: PrismaVectorStore.ContentColumn,
82 },
83 filter: {
84 accountId: { equals: accountId },
85 confidence: { equals: 100 },
86 },
87 });
88 const vectorResults = await prismaVectorStore.similaritySearch(
89 query,
90 env.CHUNKS
91 );

Callers 1

server.tsFile · 0.80

Calls 5

summarizeMethod · 0.95
askLLMMethod · 0.95
queryThreadsMethod · 0.80
mapMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected