-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearcher.py
More file actions
27 lines (21 loc) · 853 Bytes
/
Copy pathsearcher.py
File metadata and controls
27 lines (21 loc) · 853 Bytes
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
import os
from langchain_community.vectorstores import Chroma
from indexer import embeddings
def search_codebase(repo_name: str, query: str, top_k: int = 5):
persist_directory = f"./chroma_db/{repo_name}"
if not os.path.exists(persist_directory):
raise ValueError(f"Repository {repo_name} has not been indexed yet.")
vectorstore = Chroma(
persist_directory=persist_directory,
embedding_function=embeddings,
collection_name=repo_name
)
results = vectorstore.similarity_search(query, k=top_k)
formatted_results = []
for doc in results:
formatted_results.append({
"source": doc.metadata.get("source", "Unknown"),
"line": doc.metadata.get("line", 1),
"content": doc.page_content
})
return formatted_results