Skip to content

Commit e650aef

Browse files
committed
fix document listing and search in playground
1 parent 04debd0 commit e650aef

File tree

11 files changed

+22
-573
lines changed

11 files changed

+22
-573
lines changed

src/cli/playground.js

+22-4
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,9 @@ export async function startPlayground() {
233233

234234
try {
235235
const client = await rag.getClient();
236-
console.log("Using database:", rag.config.database);
237-
console.log("Using collection:", rag.config.collection);
238-
239236
const collection = client.db(rag.config.database).collection(rag.config.collection);
240237
const documents = await collection.find({}).toArray();
241-
res.json(documents);
238+
res.json({ documents });
242239
} catch (error) {
243240
console.error('Error fetching documents:', error);
244241
res.status(500).json({ error: error.message });
@@ -277,6 +274,27 @@ export async function startPlayground() {
277274
}
278275
});
279276

277+
// Add this endpoint to handle search queries
278+
app.post('/api/search', async (req, res) => {
279+
if (!rag) {
280+
return res.status(503).json({ error: "MongoDB connection not available" });
281+
}
282+
283+
const { query } = req.body;
284+
285+
try {
286+
const client = await rag.getClient();
287+
const collection = client.db(rag.config.database).collection(rag.config.collection);
288+
289+
// Perform a search using the query
290+
const results = await collection.find({ $text: { $search: query } }).toArray();
291+
res.json({ results });
292+
} catch (error) {
293+
console.error('Error performing search:', error);
294+
res.status(500).json({ error: error.message });
295+
}
296+
});
297+
280298
io.on('connection', (socket) => {
281299
socket.on('disconnect', () => {
282300
console.log('User disconnected');

test/rag-workshop/data/articles/mongodb-atlas.md

-48
This file was deleted.

test/rag-workshop/data/articles/rag-overview.md

-58
This file was deleted.

test/rag-workshop/data/qa-pairs.json

-22
This file was deleted.

test/rag-workshop/package.json

-22
This file was deleted.

test/rag-workshop/src/config.js

-30
This file was deleted.

test/rag-workshop/src/generate.js

-92
This file was deleted.

0 commit comments

Comments
 (0)