mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-10 22:41:17 +00:00
search endpoint
This commit is contained in:
parent
823e9d276f
commit
1d9446ef8c
3 changed files with 48 additions and 3 deletions
|
|
@ -171,6 +171,51 @@ app.get(
|
|||
},
|
||||
);
|
||||
|
||||
app.get(
|
||||
"/api/search",
|
||||
zValidator("query", z.object({ query: z.string(), user: z.string() })),
|
||||
async (c) => {
|
||||
const { query, user } = c.req.valid("query");
|
||||
const filter: VectorizeVectorMetadataFilter = {
|
||||
[`user-${user}`]: 1,
|
||||
};
|
||||
|
||||
const { store } = await initQuery(c);
|
||||
const queryAsVector = await store.embeddings.embedQuery(query);
|
||||
|
||||
const resp = await c.env.VECTORIZE_INDEX.query(queryAsVector, {
|
||||
topK: 5,
|
||||
filter,
|
||||
returnMetadata: true,
|
||||
});
|
||||
|
||||
const minScore = Math.min(...resp.matches.map(({ score }) => score));
|
||||
const maxScore = Math.max(...resp.matches.map(({ score }) => score));
|
||||
|
||||
// This entire chat part is basically just a dumb down version of the /api/chat endpoint.
|
||||
const normalizedData = resp.matches.map((data) => ({
|
||||
...data,
|
||||
normalizedScore:
|
||||
maxScore !== minScore
|
||||
? 1 + ((data.score - minScore) / (maxScore - minScore)) * 98
|
||||
: 50,
|
||||
}));
|
||||
|
||||
const preparedContext = normalizedData.map(
|
||||
({ metadata, score, normalizedScore }) => ({
|
||||
context: `Website title: ${metadata!.title}\nDescription: ${metadata!.description}\nURL: ${metadata!.url}\nContent: ${metadata!.text}`,
|
||||
score,
|
||||
normalizedScore,
|
||||
}),
|
||||
);
|
||||
|
||||
return c.json({
|
||||
status: "ok",
|
||||
response: preparedContext,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// This is a special endpoint for our "chatbot-only" solutions.
|
||||
// It does both - adding content AND chatting with it.
|
||||
app.post(
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const tweetToMd = (tweet: Tweet) => {
|
|||
|
||||
const BOOKMARKS_URL = `https://x.com/i/api/graphql/xLjCVTqYWz8CGSprLU349w/Bookmarks?features=${encodeURIComponent(JSON.stringify(features))}`;
|
||||
|
||||
const BACKEND_URL = "http://localhost:3000";
|
||||
const BACKEND_URL = "https://beta.supermemory.ai";
|
||||
|
||||
// This is to prevent going over the rate limit
|
||||
let lastTwitterFetch = 0;
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ function Menu() {
|
|||
height={24}
|
||||
className="hover:brightness-125 focus:brightness-125 duration-200 text-white"
|
||||
/>
|
||||
<p className="opacity-0 duration-200 group-hover:opacity-100 group-focus-within:opacity-100">
|
||||
<p className="opacity-0 duration-200 group-hover:opacity-100">
|
||||
Add
|
||||
</p>
|
||||
</DialogTrigger>
|
||||
|
|
@ -168,7 +168,7 @@ function Menu() {
|
|||
height={24}
|
||||
className="hover:brightness-125 duration-200"
|
||||
/>
|
||||
<p className="opacity-0 duration-200 group-hover:opacity-100 group-focus-within:opacity-100">
|
||||
<p className="opacity-0 duration-200 group-hover:opacity-100">
|
||||
{item.text}
|
||||
</p>
|
||||
</Link>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue