#πŸ”’ Modifying returned value -- maximize speed

4 messages Β· Page 1 of 1 (latest)

rotund umbra
#

Hey there! I am currently using LangChain + MongoDB RAG that pulls objects from the database based on a query.
Now, I only want to return a set of these returned properties:


@app.get("/find_properties")
def find_properties():
    vector_search = MongoDBAtlasVectorSearch.from_connection_string(
        os.getenv("MONGODB_URI"),
        DB_NAME + "." + COLLECTION_NAME,
        OpenAIEmbeddings(disallowed_special=()),
        index_name=ATLAS_VECTOR_SEARCH_INDEX_NAME,
    )

    search_results = vector_search.similarity_search_with_score("villa with pool", k=3)
    formatted_results = []
    for result in search_results:
        doc = result[0]
        formatted_result = {
            "page_content": doc.page_content,
            "title": doc.metadata.get("title"),
            "location": doc.metadata.get("location"),
            "price": doc.metadata.get("price"),
            "tags": doc.metadata.get("tags"),
            "sqm": doc.metadata.get("sqm"),
            "bedrooms": doc.metadata.get("bedrooms"),
            "link": doc.metadata.get("link"),
            "reference": doc.metadata.get("reference"),
            "photos": doc.metadata.get("photos"),
            "price_per_sqm": doc.metadata.get("price_per_sqm"),
            "professional_name": doc.metadata.get("professional_name"),
            "details": doc.metadata.get("details"),
            "last_update": doc.metadata.get("last_update"),
        }
        formatted_results.append(formatted_result)
        
    return formatted_results

This is how I am doing it now, but I assume going over 5 results for each query is not the best way-- how would you speed it up?

Thanks in advance.

north mangoBOT
#

@rotund umbra

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

north mangoBOT
#

@rotund umbra

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.